interface PasswordStrengthIndicatorProps { password: string; } export function PasswordStrengthIndicator({ password, }: PasswordStrengthIndicatorProps) { const getStrength = ( pwd: string, ): { level: number; label: string; color: string; requirements: string[]; } => { const requirements: string[] = []; let strength = 0; // Minimum 12 caractères (requis) if (pwd.length >= 12) { strength++; } else { requirements.push(`Au moins 12 caractères (${pwd.length}/12)`); } // Majuscule et minuscule if (/[a-z]/.test(pwd) && /[A-Z]/.test(pwd)) { strength++; } else { if (!/[a-z]/.test(pwd)) requirements.push('Une minuscule'); if (!/[A-Z]/.test(pwd)) requirements.push('Une majuscule'); } // Chiffre if (/\d/.test(pwd)) { strength++; } else { requirements.push('Un chiffre'); } // Caractère spécial if (/[^a-zA-Z\d]/.test(pwd)) { strength++; } else { requirements.push('Un caractère spécial (!@#$%^&*...)'); } let label: string; let color: string; if (strength <= 1) { label = 'Très faible'; color = 'bg-red-500'; } else if (strength === 2) { label = 'Faible'; color = 'bg-orange-500'; } else if (strength === 3) { label = 'Moyen'; color = 'bg-yellow-500'; } else if (strength === 4) { label = 'Fort'; color = 'bg-green-500'; } else { label = 'Très fort'; color = 'bg-green-600'; } return { level: strength, label, color, requirements }; }; if (!password) return null; const { level, label, color, requirements } = getStrength(password); const width = (level / 4) * 100; return (

Force: {label}

{requirements.length > 0 && (

Requis :

    {requirements.map((req, index) => (
  • {req}
  • ))}
)}
); }