P02 Lab 11 — Password Security & Breach Check
WARMUP: Chapter 15 (Cryptographic Failures); NIST 800-63.
The idea
Two engineering controls around passwords: store them with a slow, salted, memory-hard KDF (Argon2id/bcrypt/scrypt/PBKDF2 — never a fast hash like SHA-256), and screen them against breach corpora without leaking them. The breach check reproduces Have I Been Pwned's k-anonymity range query: the client sends only the first 5 hex chars of the SHA-1 hash (a prefix shared by thousands of breached hashes), the server returns the matching suffixes, and the client matches locally — so the password and its full hash never leave the client. It's a lovely intersection of crypto and privacy (the Privacy module's k-anonymity, applied to a real API).
What you build (lab.py)
kdf_strength(algo, iterations)—unacceptable(fast/unsalted hashes) /weak(PBKDF2 below the iteration floor) /strong(Argon2id/bcrypt/scrypt, or PBKDF2 with enough iterations).password_strength(pw)— deterministic length × character-class rating.sha1_hex/hash_prefix— the HIBP hash format and the 5-char prefix split.range_query(prefix, db)— server side: returns{suffix: count}for a prefix only.check_breach(pw, db)— client side: uses only a range query; returns the seen count (0 = safe).
Cases the tests cover
- KDF classification (SHA-256 unacceptable for passwords; PBKDF2 below/above the iteration floor; Argon2id strong); strength bands; the range query returns only same-prefix suffixes; breach found vs missed; and explicitly that the check works from the prefix alone (privacy-preserving).
Run
pip install -r requirements.txt
LAB_MODULE=solution pytest -q
pytest -q
Hardening / extensions
- Estimate cracking cost/time from the KDF and parameters; add per-algorithm tuning guidance.
- Use a real Argon2/bcrypt library and verify salt uniqueness and rehash-on-login-after-upgrade.
- Add passphrase/zxcvbn-style strength and a denylist of breached/common passwords at signup.
Interview / resume
"Built password-storage KDF classification and a privacy-preserving breach check that mirrors Have I Been Pwned's k-anonymity range query — the password and its full hash never leave the client — tying crypto and privacy to a real-world API."
Limitations: strength rating is a simple heuristic (not zxcvbn); breach check uses SHA-1 (the HIBP corpus format) as a lookup key only, not a security control.