vibe-cli-tool
Version:
VibeCLI v1.9 - 模板商店生态,智能部署生成,多语言支持,交互式学习系统,企业级Web全栈应用CLI工具
43 lines (33 loc) • 1.03 kB
text/typescript
import bcrypt from 'bcryptjs'
const SALT_ROUNDS = 12
export async function hashPassword(password: string): Promise<string> {
return bcrypt.hash(password, SALT_ROUNDS)
}
export async function verifyPassword(password: string, hashedPassword: string): Promise<boolean> {
return bcrypt.compare(password, hashedPassword)
}
export function validatePasswordStrength(password: string): {
isValid: boolean
errors: string[]
} {
const errors: string[] = []
if (password.length < 8) {
errors.push('密码至少需要8个字符')
}
if (!/[a-z]/.test(password)) {
errors.push('密码必须包含至少一个小写字母')
}
if (!/[A-Z]/.test(password)) {
errors.push('密码必须包含至少一个大写字母')
}
if (!/\d/.test(password)) {
errors.push('密码必须包含至少一个数字')
}
if (!/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(password)) {
errors.push('密码必须包含至少一个特殊字符')
}
return {
isValid: errors.length === 0,
errors
}
}