Password Kitchen — Security

Mix password hashing that stands up to rainbow tables and brute force: 18 levels of salts, work factors, timing attacks and threat modeling.

What you learn in this game

A good server does not store passwords, only their hash: a fingerprint you can compute from the password but cannot reverse. At login the typed password is hashed again and matched. The weakness: the same password always hashes the same, so a thief can compute the hashes of thousands of common passwords before stealing anything, then just look up. That is a rainbow table. A salt is a random string mixed into the password before hashing and stored next to the hash.

A salt that is the same for everyone is usually written in code. A thief who targets this book reads it, and then one computation per guess is enough to test all the rows at once. Two people with the same password also get the same row. A random per-user salt (from crypto.getRandomValues) makes every row different and forces the thief to compute again for each person.

A == comparison stops at the first byte that differs. A guessed hash that matches two bytes in is answered a little slower than one that differs at once, and an attacker who times the answer learns the stored hash a little at a time. A constant-time comparison checks all the bytes every time, match or not.

A thief who holds the book guesses without limit on their own device. The only brake is the cost of each guess. MD5 and SHA-256 are made as fast as possible. A password function is slow on purpose and can be tuned: Argon2id uses memory (OWASP: 19 MiB, 2 passes), bcrypt doubles the work each time its cost goes up (OWASP: at least 10), PBKDF2 repeats HMAC many times (OWASP: 600,000 rounds for SHA-256). bcrypt and Argon2id make their own random salt.

Each login computes the hash once, at the same cost as one of the thief’s guesses. Work that is too high makes the server itself choke when many people log in. Times in this game are measured on a laptop like the cash laptop (PHP 8.4 and OpenSSL): bcrypt cost 10 about 80 ms and each extra cost doubles it, PBKDF2 600,000 rounds about 75 ms, Argon2id 19 MiB about 38 ms.

bcrypt was made in 1999 and reads only the first 72 bytes of a password. A longer password is quietly cut, so anyone who knows its first 72 bytes can get in, whatever the rest is. Laravel on the server next door uses bcrypt and does not cut anything itself. Argon2id and PBKDF2 read the whole password.

What the levels ask

  1. Mix a password-storage recipe until Ms. Wulan’s cheat book finds no row at all, then run the drill.
  2. Change the recipe until Mrs. Ratna cannot test the whole book with one computation per guess.
  3. Change the way the hash is matched until the time a "wrong" takes tells Mr. Harun nothing.
  4. Resist both in one recipe.
  5. Mix the recipe until each of Bagas’s guesses costs as much as the OWASP guidance asks.
  6. Resist both: Mrs. Ratna with the whole book, Bagas with one person.
  7. Set PBKDF2’s work until Bagas is held off.
  8. Set Argon2id’s memory until Bagas is held off.
  9. Hold Bagas off with a login of at most 100 ms on the cash laptop.
  10. Resist all four in one recipe.
  11. Mix the recipe until the neighbourhood head’s whole sentence is hashed, with each guess still as costly as OWASP’s minimum.
  12. Mix a recipe that runs on the district server and holds both off.

And more, 18 levels in all.