ultisuite-client/lib/auth/password-strength.ts
R3D347HR4Y 496b1dfc1f
Some checks are pending
E2E / Playwright e2e (push) Waiting to run
feat: enhance authentication flow with new password management and signup components
- Introduced PasswordFieldBlock component for improved password input handling, including visibility toggle and strength evaluation.
- Added SignupCredentialsFields component to streamline user signup with email availability checks and password confirmation.
- Updated FlowChallengeForm to integrate new components, enhancing user experience during authentication.
- Refactored CSS styles for consistent design across authentication components, ensuring a cohesive look and feel.
2026-06-19 23:47:16 +02:00

38 lines
1023 B
TypeScript

export type PasswordStrengthLevel = "empty" | "weak" | "fair" | "good" | "strong"
export type PasswordStrength = {
level: PasswordStrengthLevel
score: number
label: string
}
export function evaluatePasswordStrength(password: string): PasswordStrength {
if (!password) {
return { level: "empty", score: 0, label: "" }
}
let score = 0
if (password.length >= 8) score += 1
if (password.length >= 12) score += 1
if (/[a-z]/.test(password) && /[A-Z]/.test(password)) score += 1
if (/\d/.test(password)) score += 1
if (/[^A-Za-z0-9]/.test(password)) score += 1
if (score <= 1) {
return { level: "weak", score, label: "Faible" }
}
if (score === 2) {
return { level: "fair", score, label: "Moyen" }
}
if (score === 3 || score === 4) {
return { level: "good", score, label: "Bon" }
}
return { level: "strong", score, label: "Fort" }
}
export function passwordsMatch(a: string, b: string): boolean | null {
if (!a && !b) return null
if (!b) return null
return a === b
}