Project: Password-Strength Estimator
"Your password must contain an upper-case letter, a digit and a symbol" produces Summer2025!, exactly the kind of password that spraying lists are built from. Composition rules measure the wrong thing: they count character classes, while attackers count guesses. A useful strength meter estimates how many guesses a realistic attacker needs, by recognising the patterns people actually use: dictionary words, capitalised first letters, leetspeak, years and keyboard walks. This project builds a small estimator with three parts (a character-set model, a blocklist and pattern models), compares their answers, and turns the estimate into a time with the lab. The policy side, how passwords are stored and attacked, is in Brute Force and Password Spraying and Applied Cryptography.
Entropy as a guess count
If a password is chosen uniformly at random from symbols with length , there are equally likely candidates, and its entropy in bits is
An attacker searching the space finds it after half of it on average, so with guesses per second the expected time is
Ten random characters from the 95 printable ASCII symbols give bits. The catch is the word random. People do not choose uniformly, so the formula applied to Summer2025! (11 characters, four classes) gives about 72 bits, while an attacker who tries common words with a capital letter, a year and a symbol needs only about a hundred million guesses. A realistic estimator therefore computes the guess count under several attacker models and keeps the smallest.
Try the effect of length, character set, hash function and attacker on the time to guess, for genuinely random passwords:
The lab's rates are illustrative orders of magnitude, not benchmarks. Notice how much the hash function matters: the same password that falls in a year against fast SHA-256 survives far longer against bcrypt, which is why storage and strength are two halves of the same defence.
The estimator
The models below are deliberately small and visible. The word lists stand in for real ones: a production estimator such as zxcvbn ships tens of thousands of common passwords, names and words.
| Model | Guess count it assumes | Bits |
|---|---|---|
| charset | every string of length over the classes used | |
| blocklist | the attacker tries known breached passwords first | 0 (reject outright) |
| dictionary + mangling | a word from a 10,000-entry list, maybe capitalised, maybe leetspeak, then digits or a year, then symbols | |
| sequence / repeat | qwertyuiop, abcdef, aaaa: a short list of patterns |
a few bits |
| passphrase | words from a 7,776-word Diceware list |
import math, re
BLOCKLIST = {"password", "123456", "12345678", "qwerty", "letmein", "iloveyou", "admin", "welcome"}
COMMON_WORDS = {"password", "dragon", "monkey", "summer", "winter", "football", "welcome", "shadow", "admin", "sunshine"}
DICT_SIZE = 10_000 # model: base words come from a 10,000-word list of common passwords
DICEWARE = {"correct", "horse", "battery", "staple", "lamp", "river", "orbit", "velvet"} # sample of a 7,776-word list
LEET = str.maketrans("@4310$5!7", "aaeiossit")
SEQS = ["abcdefghijklmnopqrstuvwxyz", "0123456789", "qwertyuiop", "asdfghjkl", "zxcvbnm"]
def charset_bits(pw):
c = 0
c += 26 if re.search(r"[a-z]", pw) else 0
c += 26 if re.search(r"[A-Z]", pw) else 0
c += 10 if re.search(r"\d", pw) else 0
c += 33 if re.search(r"[^A-Za-z0-9]", pw) else 0
return len(pw) * math.log2(c) if c else 0.0
def pattern_bits(pw):
"""Smallest guess count (as bits) under a few attacker models; None if no model applies."""
s = pw.lower()
cands = []
if len(set(pw)) == 1:
cands.append(("repeat", math.log2(95 * len(pw))))
for seq in SEQS:
for src in (seq, seq[::-1]):
if len(s) >= 3 and s in src:
cands.append(("sequence", math.log2(len(src) * len(s))))
words = s.split()
if len(words) >= 2 and all(w in DICEWARE for w in words):
cands.append(("passphrase", len(words) * math.log2(7776)))
m = re.fullmatch(r"([a-z@4310$5!7]+?)(\d*)([^a-z0-9]*)", s)
if m and m[1].translate(LEET) in COMMON_WORDS:
digits, symbols = m[2], m[3]
bits = math.log2(DICT_SIZE)
bits += 1 if pw[0].isupper() else 0
bits += 1 if m[1] != m[1].translate(LEET) else 0
if len(digits) == 4 and 1900 <= int(digits) <= 2039:
bits += math.log2(140)
else:
bits += len(digits) * math.log2(10)
bits += len(symbols) * math.log2(33)
cands.append(("dictionary+mangling", bits))
return min(cands, key=lambda c: c[1]) if cands else None
def estimate(pw):
if pw.lower() in BLOCKLIST:
return 0.0, "blocklisted"
naive = charset_bits(pw)
pat = pattern_bits(pw)
if pat and pat[1] < naive:
return pat[1], pat[0]
return naive, "charset (assumes uniform choice)"
for pw in ["password", "Summer2025!", "P@ssw0rd", "qwertyuiop", "aaaaaaaaaaaa",
"correct horse battery staple", "tR7#qL9vX2", "k9vX!2mQ#pL8zR4w"]:
bits, why = estimate(pw)
verdict = "reject" if bits < 40 else "weak" if bits < 60 else "ok"
print(f"{pw!r:32} naive {charset_bits(pw):6.1f} estimate {bits:6.1f} bits {verdict:<6} ({why})")
R = 1e10 # illustrative: one GPU against unsalted SHA-256
for bits in (26.5, 51.7, 65.7):
print(f"{bits:5.1f} bits at 1e10 guesses/s: {2 ** (bits - 1) / R:.3g} s on average")'password' naive 37.6 estimate 0.0 bits reject (blocklisted)
'Summer2025!' naive 72.3 estimate 26.5 bits reject (dictionary+mangling)
'P@ssw0rd' naive 52.6 estimate 15.3 bits reject (dictionary+mangling)
'qwertyuiop' naive 47.0 estimate 6.6 bits reject (sequence)
'aaaaaaaaaaaa' naive 56.4 estimate 10.2 bits reject (repeat)
'correct horse battery staple' naive 164.7 estimate 51.7 bits weak (passphrase)
'tR7#qL9vX2' naive 65.7 estimate 65.7 bits ok (charset (assumes uniform choice))
'k9vX!2mQ#pL8zR4w' naive 105.1 estimate 105.1 bits ok (charset (assumes uniform choice))
26.5 bits at 1e10 guesses/s: 0.00475 s on average
51.7 bits at 1e10 guesses/s: 1.83e+05 s on average
65.7 bits at 1e10 guesses/s: 3e+09 s on average
The naive charset numbers are the "composition rule" view; the estimates are the attacker's view. Summer2025! drops from 72 bits to about 26.5: for the word, 1 bit for the capital, for a year between 1900 and 2039 and for one symbol. At ten billion guesses a second that is a few milliseconds. The four-word passphrase is rated on the passphrase model, bits, far below its naive 164.7 bits but still about seconds (two days) on average at the same rate, and tens of thousands of years at the lab's bcrypt rate; five or six words are better. The two random strings get the full charset estimate because no pattern explains them: that is the only case where the formula is honest.
How weak passwords are detected
- At the moment of choice: the estimator runs when a password is set or changed, and the blocklist check uses a large breached-password corpus (the k-anonymity range query from Brute Force and Password Spraying keeps the password private).
- In audits of your own systems: check that the policy is enforced in code (minimum length, blocklist), and look for shared or default passwords in configuration files and scripts with secret scanners. Testing users' stored hashes against wordlists is a formal, authorised activity with its own rules; it is not part of this course.
- From the outside: spraying and stuffing attempts in the logs (log analyser) show which accounts attackers think are weak.
How it is fixed
NIST SP 800-63B Revision 4 (2025) sets the modern baseline for verifiers:
- Length over composition: at least 15 characters for passwords used as the only factor (8 when part of multi-factor authentication), accept at least 64, allow spaces and all printable characters, and no composition rules such as "one symbol".
- Blocklist every new password against breached, common and context-specific values (the service name, the user name).
- No forced periodic changes; change on evidence of compromise.
- Show the estimate, not a rule list: a meter based on guess counts teaches users to pick passphrases.
- Slow, salted hashing (Argon2id, scrypt, bcrypt, PBKDF2) and MFA, because even good passwords get phished.
Pitfalls
- Entropy of a random process is not the entropy of a string.
tR7#qL9vX2is strong only if it really was generated randomly; the same characters chosen as "my cat's name with substitutions" are not. - Overfitting the meter: users learn to satisfy it (add
!1), so estimate patterns and blocklist mangled variants too. - Sending passwords to a third-party meter leaks them; run the estimator locally.
- Truncation: bcrypt uses only the first 72 bytes, so a 100-character passphrase is effectively 72 bytes there.
Practice
1. Compute the charset estimate for a 12-character password of lower-case letters and digits, and the expected time at 1e10 guesses per second if it was chosen randomly.
, bits, seconds, about 7.5 years.
2. What does the estimator say for Dragon1990$? Work it out from the model before running it.
Dictionary word dragon (13.3 bits) + capital (1) + year 1990 (7.1) + one symbol (5.0) = about 26.5 bits: reject. The naive estimate would be bits.
3. How many Diceware words do you need for at least 77 bits?
gives (6 words: about 77.5 bits).
Practice problem in 21 languages: Password Entropy Estimate.
Test yourself
A password is chosen uniformly at random from 62 symbols with length 10. What is its entropy?
- bits
- bits
- bits
- 62 bits
Why does the estimator rate Summer2025! far lower than its charset estimate?
- It is too short
- It matches the dictionary-plus-mangling model: a common word, a capital, a year and a symbol
- It contains a space
- It is in the passphrase list
Under NIST SP 800-63B Revision 4, which is a requirement for single-factor passwords?
- One upper-case letter, one digit and one symbol
- A forced change every 90 days
- At least 15 characters and a blocklist check
- A maximum length of 16
With guesses per second and bits, the expected time to guess a random password is: