All files / src/utils authUtils.ts

100% Statements 25/25
87.5% Branches 7/8
100% Functions 2/2
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 202x 2x 2x 2x 2x 2x 2x 2x 2x 39x 2x 2x 168x 2x 168x 9x 39x 39x 159x 1x
// src/utils/authUtils.ts
import zxcvbn from 'zxcvbn';
 
/**
 * Validates the strength of a password using zxcvbn.
 * @param password The password to validate.
 * @returns An object with `isValid` and a feedback message.
 */
export function validatePasswordStrength(password: string): {
  isValid: boolean;
  feedback: string;
} {
  const result = zxcvbn(password);
  // Score: 0-4. We require at least 3.
  if (result.score < 3) {
    const suggestions = result.feedback.suggestions.join(' ');
    return { isValid: false, feedback: `Password is too weak. ${suggestions}` };
  }
  return { isValid: true, feedback: '' };
}