Password Policy & Strength
Old password rules ("8 characters, one uppercase, one digit, one symbol, change it every 90 days") produced passwords like Summer2025! that are hard to remember and easy to guess. Modern guidance, such as NIST SP 800-63B, takes a different approach: long passwords, no forced complexity, no periodic changes without a reason, and a check against passwords that are already known to be bad.
| Old rule | Modern guidance | Reason |
|---|---|---|
| Minimum 8 characters | Minimum 8, better 15+; allow at least 64 | Length adds the most strength |
| Must mix character classes | Don't require composition rules | People respond with predictable patterns (Password1!) |
| Change every 90 days | Change only on evidence of compromise | Forced changes lead to Spring2025 → Summer2025 |
| No pasting | Allow paste and password managers | Managers produce the strongest passwords |
| Hints and security questions | Don't use them | Answers are often public (mother's maiden name) |
| — | Block known-breached and common passwords | These are what attackers try first |
Measuring strength with entropy
For a password chosen at random, strength is measured in bits of entropy: length × log2(alphabet size). Each extra bit doubles the number of possibilities.
import math
def entropy_bits(length, alphabet_size):
return length * math.log2(alphabet_size)
ALPHABETS = {"digits": 10, "lowercase": 26, "letters+digits": 62, "printable": 94}
print(f"{'length':>6} " + " ".join(f"{name:>15}" for name in ALPHABETS))
for length in (8, 12, 16, 20):
row = " ".join(f"{entropy_bits(length, size):>15.1f}" for size in ALPHABETS.values())
print(f"{length:>6} {row}")length digits lowercase letters+digits printable
8 26.6 37.6 47.6 52.4
12 39.9 56.4 71.5 78.7
16 53.2 75.2 95.3 104.9
20 66.4 94.0 119.1 131.1
Notice that a 16-character lowercase password (75 bits) beats a 10-character "complex" one: 10 × log2(94) ≈ 65.5 bits. Length beats complexity.
Passphrases
A passphrase of several random words from a large list (the classic diceware list has 7,776 words) is long, strong and memorable. The important word is random: words picked by a person ("ilovemydog") are much weaker.
import math
WORDLIST_SIZE = 7776
for words in range(3, 8):
bits = words * math.log2(WORDLIST_SIZE)
print(f"{words} diceware words: {bits:5.1f} bits")3 diceware words: 38.8 bits
4 diceware words: 51.7 bits
5 diceware words: 64.6 bits
6 diceware words: 77.5 bits
7 diceware words: 90.5 bits
Note: Entropy formulas only apply to randomly generated secrets. For human-chosen passwords they badly overestimate strength, because people pick common words, names, dates and keyboard patterns. That's why a blocklist check matters more than a complexity rule.
A modern password checker
The checker below follows NIST-style rules: a minimum length, a maximum that's generous enough for passphrases, a blocklist of common passwords, and context checks (the password must not contain the username or the site name). In production the blocklist would contain millions of entries from breach corpora, often checked through a privacy-preserving service; here a short list stands in for it.
import unicodedata
COMMON = {"password", "123456", "123456789", "qwerty", "iloveyou",
"letmein", "admin", "welcome", "monkey", "dragon"}
def normalise(pw):
# NFKC so that visually identical inputs are treated the same
return unicodedata.normalize("NFKC", pw)
def check_password(pw, username, site="tadshop"):
pw = normalise(pw)
problems = []
if len(pw) < 12:
problems.append("use at least 12 characters")
if len(pw) > 128:
problems.append("use at most 128 characters")
lowered = pw.lower()
stripped = lowered.rstrip("0123456789!?.")
if lowered in COMMON or stripped in COMMON:
problems.append("this is a very common password")
if username.lower() in lowered:
problems.append("don't include your username")
if site in lowered:
problems.append("don't include the site name")
if len(set(pw)) <= 2:
problems.append("too repetitive")
return problems
tests = [
("alice", "qwerty"),
("alice", "Password123!"),
("alice", "alice-2025-rocks"),
("bob", "tadshop-bob-login"),
("carol", "aaaaaaaaaaaaaaaa"),
("dave", "orbit kettle velvet sunrise"),
]
for user, pw in tests:
problems = check_password(pw, user)
verdict = "OK" if not problems else "; ".join(problems)
print(f"{pw!r:<32} {verdict}")'qwerty' use at least 12 characters; this is a very common password
'Password123!' this is a very common password
'alice-2025-rocks' don't include your username
'tadshop-bob-login' don't include your username; don't include the site name
'aaaaaaaaaaaaaaaa' too repetitive
'orbit kettle velvet sunrise' OK
Password123! passes every old-fashioned complexity rule (upper, lower, digit, symbol) yet is rejected here, because stripping the trailing digits and symbol reveals password. The random four-word passphrase passes.
Policy beyond the password
A password policy is more than a string check:
- Rate limiting and lockout: slow down repeated failures (per account and per source) so online guessing is impractical, without letting attackers lock real users out forever.
- MFA: makes a stolen password insufficient on its own (next section of the course).
- Breach response: force a reset only when there is evidence a password is compromised.
- Password managers: encourage them; allow paste in password fields.
- Safe storage: a slow, salted KDF (previous lesson).
Go further: Password Entropy and the Cost of Guessing has a lab that turns length, alphabet and hash choice into a time to crack.
Test yourself
According to modern guidance (NIST SP 800-63B), when should users be forced to change their password?
- Every 90 days
- Every year
- Only when there is evidence it was compromised
- Never, under any circumstances
Which randomly generated password has more entropy?
- 10 characters from 94 printable symbols
- 16 lowercase letters
- They are exactly equal
- It can't be computed
Why is a blocklist of common/breached passwords more useful than complexity rules?
- It's faster to check
- Attackers try common and breached passwords first, and complexity rules don't stop them
- Complexity rules are illegal
- Blocklists add entropy