Skip to content
Tutorials Center
My learning

Topics

Lesson 19 of 80 ยท Authentication and Access Control

Password Strength and Policies

Understand password entropy, why length beats complexity rules, what NIST recommends, and how to build a strength estimator and a breached-password check in Python.

Good storage (Password Storage Done Right) limits the damage of a leak, but it cannot save a password that an attacker guesses in the first ten tries. "Strength" simply means: how many guesses does it take before an attacker finds this password, given what attackers actually try?

For decades the standard answer was a policy: at least eight characters, one capital letter, one digit, one symbol, change it every 90 days. Research and real breach data showed that these rules mostly make people choose Password1! and then Password2!. Modern guidance, including the US NIST digital identity guidelines (SP 800-63B), turned almost all of them around. In this lesson you will measure entropy, see why attackers do not guess randomly, build a pattern-aware estimator, and add a breached-password check that never reveals the password.

Entropy: counting possibilities

If a password is chosen uniformly at random from a set of N possibilities, its entropy is log2(N) bits. Each extra bit doubles the attacker's work. For a random string of length L from an alphabet of size A, entropy is L x log2(A).

The key word is random. A tool or dice can generate randomness; a human typing Tr0ub4dor&3 cannot. The formula below is therefore an upper bound for human-chosen text and a precise figure only for machine-generated secrets.

How long is "long enough"? It depends on the attacker's speed:

  • Online guessing against your login form is slow (maybe 10 per second per account before throttling and lockouts kick in).
  • Offline cracking of a stolen hash depends on how well you hashed it: roughly 10 billion guesses per second per GPU for a fast hash, but only thousands per second for a well-tuned Argon2id.
Python Entropy and time to guess

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice two things. First, length adds far more than extra symbol types: 16 random lowercase letters (about 75 bits) beat 8 characters drawn from all 94 printable ones (about 52 bits). Second, four random words are easy to remember and already stronger than eight random characters. Six random words are out of reach for any realistic offline attack.

Attackers do not guess randomly

Real cracking tools run through, in order of likelihood: previously breached passwords, dictionary words, names, and mutations of those (capitalize the first letter, append 1 or !, replace a with @, add a year). They also try keyboard walks like qwerty and 1qaz2wsx, repeated chunks like abcabc, and dates.

So a password that looks complex may carry very little real entropy. Summer2024! has a capital, lowercase letters, digits and a symbol, yet it is a dictionary word plus a season-year pattern plus a common suffix, and falls within the first few million guesses of any decent tool.

A good estimator therefore does not count character classes; it searches for the cheapest way an attacker could produce the password and reports that cost. Production libraries such as zxcvbn (originally from Dropbox) do this with large frequency lists. The small estimator below uses the same idea with a tiny, made-up dictionary so that you can see every step.

Python A pattern-aware strength estimator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Look at the classes column: Password1! and Summer2024! score 4 out of 4 under the old rules but come out very weak once patterns are accounted for (and aaaaaaaaaaaa collapses to a single repeated character), while a plain four-word passphrase with only lowercase letters and spaces scores low on classes yet clearly stronger on bits. The estimator is a teaching tool, not a security product: use zxcvbn or a similar maintained library in real systems.

What modern policy guidance says

NIST SP 800-63B (and similar guidance from the UK NCSC and OWASP) recommends the following for passwords people choose themselves:

  • Minimum length of 8, and prefer 15 or more when the password is the only factor. Allow at least 64 characters so passphrases fit.
  • No composition rules. Do not demand a mix of upper case, digits and symbols; they push users toward predictable substitutions.
  • No forced periodic changes. Require a change only when there is evidence of compromise. Frequent rotation produces Password1, Password2, ...
  • Check against a blocklist of passwords known from breaches, common words, context-specific words (the username, the service name) and sequences like abcd1234.
  • Allow all printable characters, spaces and Unicode, and allow paste and password managers.
  • Show a strength meter that gives useful feedback ("this is a common pattern") rather than a green bar that rewards Password1!.
  • Do not use password hints or knowledge-based questions ("mother's maiden name"), whose answers are guessable or public.
  • Rate-limit guesses and add multi-factor authentication so that the strength of one password is not the only barrier.
flowchart TD
    A["User submits a new password"] --> B{"Length ok?<br/>8+ (15+ if no MFA), max 64+"}
    B -- no --> X["Reject with a clear reason"]
    B -- yes --> C{"On the breached or<br/>common-password blocklist?"}
    C -- yes --> X
    C -- no --> D{"Contains username,<br/>email or service name?"}
    D -- yes --> X
    D -- no --> E["Accept and hash with Argon2id,<br/>scrypt, bcrypt or PBKDF2"]

A modern password check rejects known-bad choices instead of demanding special characters.

Checking breached passwords without revealing them

The best blocklist is the set of real passwords exposed in breaches. Services such as Have I Been Pwned expose a range API built on k-anonymity, so you can check a password without ever sending it:

  1. Compute the SHA-1 hash of the password locally. (SHA-1 is acceptable here: it is only a lookup key into a public list, not a storage format.)
  2. Send only the first five hex characters of the hash.
  3. The service returns every known suffix in that bucket, together with a breach count. Several hundred suffixes come back, so the server cannot tell which one you care about.
  4. Compare the remaining 35 characters locally.

The demo simulates the service with a small made-up database of breached hashes, so no network is needed:

Python k-anonymity range lookup (simulated)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In production, the same two functions call https://api.pwnedpasswords.com/range/<prefix> over HTTPS. Because the check happens when the user sets a password, an outage of that service should not block sign-ups: fail open for a short time, but log it.

Passphrases and password managers

For the user, the best advice is short and practical. Use a password manager and let it generate a unique random password for every site, so that one breach never unlocks another account. Memorize only the manager's master passphrase and your device unlock; make the master passphrase four to six random words. Where possible, turn on passkeys or a second factor.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. A password is chosen uniformly at random from 2^40 possibilities. What is its entropy?

    Entropy is log2 of the number of equally likely possibilities, so 2^40 possibilities give 40 bits. Each extra bit doubles the work.
  2. 2. Which password change would modern NIST guidance support?

    NIST recommends length, blocklists and allowing paste, and advises against composition rules, routine expiry and knowledge-based questions.
  3. 3. Why does 'Summer2024!' offer much less protection than its character classes suggest?

    Cracking tools try words plus mutations such as years and trailing symbols early, so the true search space is tiny compared with 11 random characters.
  4. 4. What does a client send to the k-anonymity range API?

    Only a short prefix is sent. The service answers with all suffixes in that bucket and the client matches its own suffix locally, so the password stays private.
  5. 5. A site stores passwords correctly with Argon2id. Why still check for weak or breached passwords?

    Slow hashing raises the cost per guess, but attackers try the most likely passwords first, and online guessing needs only a handful of attempts.

Summary

  • Entropy counts possibilities: log2(N) bits for a random choice; length adds more than extra character types.
  • Humans are not random, so attackers guess breached passwords, dictionary words and common mutations first.
  • Character-class rules and forced rotation backfire; length, blocklists and a useful strength meter work better.
  • Check new passwords against breach corpora using k-anonymity so the password is never revealed.
  • Recommend password managers and random passphrases, and back passwords with rate limiting and MFA.

Next: Multi-Factor Authentication and Passkeys, where you'll add a second proof of identity.