Vanilla JavaScript Projects

Project 66, Forms and input

Password Strength Meter

Help people pick a password that is actually strong. The meter explains what is missing, spots common passwords and can make a strong one for you.

Main API
crypto.getRandomValues
Scoring
Entropy and patterns
Dependencies
None
Your browser
Checking

Try a password

Type a password and watch the meter and checklist. Try password123 or summer2024. Nothing leaves your browser.

Type a password
  • At least 12 characters
  • A lowercase letter
  • An uppercase letter
  • A number
  • A symbol like ! or #
  • Not a common password

How it works

  1. Check the basicsSimple tests look for length, lower and upper case letters, numbers and symbols, and tick the checklist live.
  2. Estimate real strengthLength times the size of the character pool gives bits of entropy. Repeats, sequences, years and common words lower the score.
  3. Generate safelyThe generator uses crypto.getRandomValues, not Math.random, so suggested passwords are truly unpredictable.
function entropy(p) {
  const pool = (/[a-z]/.test(p) ? 26 : 0) + (/[A-Z]/.test(p) ? 26 : 0)
             + (/\d/.test(p) ? 10 : 0) + (/[^A-Za-z0-9]/.test(p) ? 32 : 0);
  return p.length * Math.log2(pool || 1);      // bits
}
function randomIndex(n) {
  const a = new Uint32Array(1);
  crypto.getRandomValues(a);                    // secure, unlike Math.random
  return a[0] % n;
}