@longzai-intelligence-auth/hashing 0.0.1 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.mts +18 -0
- package/dist/index.mjs +1 -0
- package/package.json +18 -5
- package/dist/bun-password-hasher.d.ts +0 -5
- package/dist/bun-password-hasher.js +0 -9
- package/dist/hash.d.ts +0 -2
- package/dist/hash.js +0 -17
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/policy.d.ts +0 -3
- package/dist/policy.js +0 -28
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("argon2");async function t(t){return(0,e.hash)(t,{type:2,memoryCost:65536,timeCost:3,parallelism:4})}async function n(t,n){try{return await(0,e.verify)(n,t)}catch{return!1}}const r={minLength:8,requireUppercase:!0,requireLowercase:!0,requireNumber:!0,requireSpecial:!1,historyCount:0,expireDays:0};function i(e,t=r){let n=[];return e.length<t.minLength&&n.push(`密码长度不能少于 ${t.minLength} 位`),t.requireUppercase&&!/[A-Z]/.test(e)&&n.push(`密码必须包含至少一个大写字母`),t.requireLowercase&&!/[a-z]/.test(e)&&n.push(`密码必须包含至少一个小写字母`),t.requireNumber&&!/[0-9]/.test(e)&&n.push(`密码必须包含至少一个数字`),t.requireSpecial&&!/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(e)&&n.push(`密码必须包含至少一个特殊字符`),{valid:n.length===0,errors:n}}var a=class{constructor(){}async hash(e){return t(e)}async verify(e,t){return n(e,t)}};exports.BunPasswordHasher=a,exports.DEFAULT_PASSWORD_POLICY=r,exports.hashPassword=t,exports.validatePasswordPolicy=i,exports.verifyPassword=n;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PasswordHasher, PasswordPolicyConfig, PasswordValidationResult } from "@longzai-intelligence-auth/core";
|
|
2
|
+
|
|
3
|
+
//#region src/hash.d.ts
|
|
4
|
+
declare function hashPassword(password: string): Promise<string>;
|
|
5
|
+
declare function verifyPassword(password: string, hashedPassword: string): Promise<boolean>;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/policy.d.ts
|
|
8
|
+
declare const DEFAULT_PASSWORD_POLICY: PasswordPolicyConfig;
|
|
9
|
+
declare function validatePasswordPolicy(password: string, policy?: PasswordPolicyConfig): PasswordValidationResult;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/bun-password-hasher.d.ts
|
|
12
|
+
declare class BunPasswordHasher implements PasswordHasher {
|
|
13
|
+
constructor();
|
|
14
|
+
hash(password: string): Promise<string>;
|
|
15
|
+
verify(password: string, hashedPassword: string): Promise<boolean>;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { BunPasswordHasher, DEFAULT_PASSWORD_POLICY, hashPassword, validatePasswordPolicy, verifyPassword };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PasswordHasher, PasswordPolicyConfig, PasswordValidationResult } from "@longzai-intelligence-auth/core";
|
|
2
|
+
|
|
3
|
+
//#region src/hash.d.ts
|
|
4
|
+
declare function hashPassword(password: string): Promise<string>;
|
|
5
|
+
declare function verifyPassword(password: string, hashedPassword: string): Promise<boolean>;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/policy.d.ts
|
|
8
|
+
declare const DEFAULT_PASSWORD_POLICY: PasswordPolicyConfig;
|
|
9
|
+
declare function validatePasswordPolicy(password: string, policy?: PasswordPolicyConfig): PasswordValidationResult;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/bun-password-hasher.d.ts
|
|
12
|
+
declare class BunPasswordHasher implements PasswordHasher {
|
|
13
|
+
constructor();
|
|
14
|
+
hash(password: string): Promise<string>;
|
|
15
|
+
verify(password: string, hashedPassword: string): Promise<boolean>;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { BunPasswordHasher, DEFAULT_PASSWORD_POLICY, hashPassword, validatePasswordPolicy, verifyPassword };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{hash as e,verify as t}from"argon2";async function n(t){return e(t,{type:2,memoryCost:65536,timeCost:3,parallelism:4})}async function r(e,n){try{return await t(n,e)}catch{return!1}}const i={minLength:8,requireUppercase:!0,requireLowercase:!0,requireNumber:!0,requireSpecial:!1,historyCount:0,expireDays:0};function a(e,t=i){let n=[];return e.length<t.minLength&&n.push(`密码长度不能少于 ${t.minLength} 位`),t.requireUppercase&&!/[A-Z]/.test(e)&&n.push(`密码必须包含至少一个大写字母`),t.requireLowercase&&!/[a-z]/.test(e)&&n.push(`密码必须包含至少一个小写字母`),t.requireNumber&&!/[0-9]/.test(e)&&n.push(`密码必须包含至少一个数字`),t.requireSpecial&&!/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(e)&&n.push(`密码必须包含至少一个特殊字符`),{valid:n.length===0,errors:n}}var o=class{constructor(){}async hash(e){return n(e)}async verify(e,t){return r(e,t)}};export{o as BunPasswordHasher,i as DEFAULT_PASSWORD_POLICY,n as hashPassword,a as validatePasswordPolicy,r as verifyPassword};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@longzai-intelligence-auth/hashing",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"license": "
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"license": "UNLICENSED",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
@@ -32,14 +32,27 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"argon2": "^0.41.0",
|
|
35
|
-
"@longzai-intelligence-auth/core": "0.0.
|
|
35
|
+
"@longzai-intelligence-auth/core": "0.0.4"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
|
-
"build": "
|
|
39
|
-
"
|
|
38
|
+
"build": "bun build src/index.ts --outdir dist --target bun",
|
|
39
|
+
"build:declaration": "tsgo --declaration --emitDeclarationOnly --outDir dist -p tsconfig/app.json",
|
|
40
|
+
"build:prod": "NODE_ENV=production tsdown",
|
|
41
|
+
"prepublishOnly": "bun run build:prod",
|
|
42
|
+
"typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
|
|
43
|
+
"typecheck:app": "tsgo --noEmit -p tsconfig/app.json",
|
|
44
|
+
"typecheck:node": "tsgo --noEmit -p tsconfig/node.json",
|
|
45
|
+
"typecheck:test": "tsgo --noEmit -p tsconfig/test.json",
|
|
40
46
|
"lint": "oxlint && oxfmt --check",
|
|
41
47
|
"lint:fix": "oxlint --fix && oxfmt",
|
|
42
48
|
"test": "bun test",
|
|
49
|
+
"test:watch": "bun test --watch",
|
|
50
|
+
"test:coverage": "bun test --coverage",
|
|
51
|
+
"test:unit": "bun test src/__tests__/unit/",
|
|
52
|
+
"test:integration": "bun test src/__tests__/integration/",
|
|
43
53
|
"clean": "rm -rf dist out .cache"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/bun": "^1.3.14"
|
|
44
57
|
}
|
|
45
58
|
}
|
package/dist/hash.d.ts
DELETED
package/dist/hash.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { hash, verify } from "argon2";
|
|
2
|
-
export async function hashPassword(password) {
|
|
3
|
-
return hash(password, {
|
|
4
|
-
type: 2,
|
|
5
|
-
memoryCost: 65536,
|
|
6
|
-
timeCost: 3,
|
|
7
|
-
parallelism: 4,
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
export async function verifyPassword(password, hashedPassword) {
|
|
11
|
-
try {
|
|
12
|
-
return await verify(hashedPassword, password);
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
}
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
package/dist/policy.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { PasswordPolicyConfig, PasswordValidationResult } from "@longzai-intelligence-auth/core";
|
|
2
|
-
export declare const DEFAULT_PASSWORD_POLICY: PasswordPolicyConfig;
|
|
3
|
-
export declare function validatePasswordPolicy(password: string, policy?: PasswordPolicyConfig): PasswordValidationResult;
|
package/dist/policy.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_PASSWORD_POLICY = {
|
|
2
|
-
minLength: 8,
|
|
3
|
-
requireUppercase: true,
|
|
4
|
-
requireLowercase: true,
|
|
5
|
-
requireNumber: true,
|
|
6
|
-
requireSpecial: false,
|
|
7
|
-
historyCount: 0,
|
|
8
|
-
expireDays: 0,
|
|
9
|
-
};
|
|
10
|
-
export function validatePasswordPolicy(password, policy = DEFAULT_PASSWORD_POLICY) {
|
|
11
|
-
const errors = [];
|
|
12
|
-
if (password.length < policy.minLength) {
|
|
13
|
-
errors.push(`密码长度不能少于 ${policy.minLength} 位`);
|
|
14
|
-
}
|
|
15
|
-
if (policy.requireUppercase && !/[A-Z]/.test(password)) {
|
|
16
|
-
errors.push("密码必须包含至少一个大写字母");
|
|
17
|
-
}
|
|
18
|
-
if (policy.requireLowercase && !/[a-z]/.test(password)) {
|
|
19
|
-
errors.push("密码必须包含至少一个小写字母");
|
|
20
|
-
}
|
|
21
|
-
if (policy.requireNumber && !/[0-9]/.test(password)) {
|
|
22
|
-
errors.push("密码必须包含至少一个数字");
|
|
23
|
-
}
|
|
24
|
-
if (policy.requireSpecial && !/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(password)) {
|
|
25
|
-
errors.push("密码必须包含至少一个特殊字符");
|
|
26
|
-
}
|
|
27
|
-
return { valid: errors.length === 0, errors };
|
|
28
|
-
}
|