@longzai-intelligence-auth/hashing 0.0.1
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/bun-password-hasher.d.ts +5 -0
- package/dist/bun-password-hasher.js +9 -0
- package/dist/hash.d.ts +2 -0
- package/dist/hash.js +17 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/policy.d.ts +3 -0
- package/dist/policy.js +28 -0
- package/package.json +45 -0
package/dist/hash.d.ts
ADDED
package/dist/hash.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
ADDED
package/dist/index.js
ADDED
package/dist/policy.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@longzai-intelligence-auth/hashing",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/index.d.cts",
|
|
18
|
+
"default": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/longzai/longzai-intelligence-auth",
|
|
31
|
+
"directory": "packages/hashing"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"argon2": "^0.41.0",
|
|
35
|
+
"@longzai-intelligence-auth/core": "0.0.1"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsgo --build",
|
|
39
|
+
"typecheck": "tsgo --noEmit",
|
|
40
|
+
"lint": "oxlint && oxfmt --check",
|
|
41
|
+
"lint:fix": "oxlint --fix && oxfmt",
|
|
42
|
+
"test": "bun test",
|
|
43
|
+
"clean": "rm -rf dist out .cache"
|
|
44
|
+
}
|
|
45
|
+
}
|