import { useMemo } from 'react'; import { cn } from '@/lib/utils'; import { validatePasswordStrength } from '@/lib/passwordValidator'; interface PasswordStrengthIndicatorProps { password: string; } interface PasswordStrength { score: number; // 0-5 checks: { length: boolean; upper: boolean; lower: boolean; number: boolean; special: boolean; }; } export function PasswordStrengthIndicator({ password }: PasswordStrengthIndicatorProps) { // T0197: Use validatePasswordStrength from passwordValidator const strength = useMemo(() => { const validation = validatePasswordStrength(password); const score = (validation.strength.length ? 1 : 0) + (validation.strength.upper ? 1 : 0) + (validation.strength.lower ? 1 : 0) + (validation.strength.number ? 1 : 0) + (validation.strength.special ? 1 : 0); return { score, checks: validation.strength, }; }, [password]); const strengthLabels = ['Very Weak', 'Weak', 'Fair', 'Good', 'Strong']; const strengthColors = [ 'bg-red-500', 'bg-orange-500', 'bg-yellow-500', 'bg-blue-500', 'bg-green-500', ]; const strengthTextColors = [ 'text-red-600', 'text-orange-600', 'text-yellow-600', 'text-blue-600', 'text-green-600', ]; if (!password) return null; const currentStrengthLabel = strengthLabels[strength.score - 1] || 'Very Weak'; const currentStrengthColor = strengthColors[strength.score - 1] || 'bg-gray-400'; const currentTextColor = strengthTextColors[strength.score - 1] || 'text-gray-600'; return (
{currentStrengthLabel}
  • {strength.checks.length ? '✓' : '○'} At least 8 characters
  • {strength.checks.upper ? '✓' : '○'} One uppercase letter
  • {strength.checks.lower ? '✓' : '○'} One lowercase letter
  • {strength.checks.number ? '✓' : '○'} One number
  • {strength.checks.special ? '✓' : '○'} One special character
); }