Publish Docker image / build-and-push (push) Canceled after 0s
ci / ci (22, ubuntu-latest) (push) Canceled after 0s
Multi-user image hosting with RBAC, upload preferences, and admin settings.
40 lines
966 B
TypeScript
40 lines
966 B
TypeScript
export const PASSWORD_MIN_LENGTH = 8
|
|
|
|
export interface PasswordCriteria {
|
|
minLength: boolean
|
|
mixedCase: boolean
|
|
hasNumber: boolean
|
|
hasSpecial: boolean
|
|
}
|
|
|
|
export type PasswordStrengthLabel = '弱' | '中' | '强'
|
|
|
|
export function analyzePassword(password: string): {
|
|
criteria: PasswordCriteria
|
|
score: number
|
|
label: PasswordStrengthLabel
|
|
isValid: boolean
|
|
} {
|
|
const criteria: PasswordCriteria = {
|
|
minLength: password.length >= PASSWORD_MIN_LENGTH,
|
|
mixedCase: /[a-z]/.test(password) && /[A-Z]/.test(password),
|
|
hasNumber: /\d/.test(password),
|
|
hasSpecial: /[^a-zA-Z0-9]/.test(password)
|
|
}
|
|
|
|
const score = Object.values(criteria).filter(Boolean).length
|
|
const label: PasswordStrengthLabel
|
|
= score <= 1 ? '弱' : score <= 3 ? '中' : '强'
|
|
|
|
return {
|
|
criteria,
|
|
score,
|
|
label,
|
|
isValid: criteria.minLength
|
|
}
|
|
}
|
|
|
|
export function isPasswordValid(password: string): boolean {
|
|
return analyzePassword(password).isValid
|
|
}
|