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 }