Lion Cipher Lab
Store passwords securely with bcrypt and Argon2
- Identity & Access Management
- Intermediate
- ~45 min
- Free · no account required
Why it matters
Storing a password is the most security-critical line of code most developers ever write, and it is deceptively easy to get catastrophically wrong. Reach for the 'obvious' tools — save the password as-is, or run it through a fast hash like SHA-256 or MD5 — and a single database leak hands attackers the accounts of everyone who reused that password anywhere else. The reason is concrete and worth feeling rather than memorizing: fast hashes are deterministic (the same password always produces the same hash, so a leak instantly reveals which users share a password and lets attackers match against…
What you'll learn
- explaining why a fast hash like SHA-256 is the WRONG tool for passwords: it is deterministic and cheap, so identical passwords collide and an attacker's GPU tries billions of guesses per second
- defining hash, salt, pepper, cost factor, and memory-hardness in plain language, and knowing which of these a password hash must have
- hashing a password with bcrypt in Python (bcrypt.hashpw with bcrypt.gensalt) and verifying it with bcrypt.checkpw
- reading the bcrypt $2b$12$... string as its parts — algorithm, cost factor, salt, and hash — and knowing about the 72-byte input truncation caveat
- hashing a password with Argon2id (argon2-cffi PasswordHasher) and verifying it, and reading the $argon2id$v=19$m=,t=,p=$ parameters
- seeing that the SAME password hashed twice produces DIFFERENT outputs, because each library generates a fresh random salt automatically
- using check_needs_rehash to transparently upgrade a stored hash when you raise the cost, and tuning cost to target ~50-250 ms per hash on your own hardware
- choosing between bcrypt, Argon2id, and scrypt/PBKDF2, and knowing these are for PASSWORDS only — never for API tokens or session ids
Steps in this lab
- The problem, and the ground rules
- Set up: confirm Python, make a clean sandbox, install the libraries
- See the wrong way, concretely: plaintext, then a fast deterministic hash
- The right way #1: bcrypt (battle-tested, salt baked in)
- The right way #2: Argon2id (the modern winner, memory-hard)
- Tune the cost and upgrade transparently
- The judgment: pepper, don't roll your own, and which algorithm when
- What you did — and the reflex to keep