From worst to best
| Method | What's stored | If the database is stolen… |
|---|---|---|
| never Plaintext | The password itself. | Every password is exposed immediately, and reused passwords unlock other sites. |
| never Encrypted | The password encrypted with a key held by the server. | The key is usually on the same server. Steal both and you decrypt everything. Encryption is reversible by design, which is exactly what you don't want here. |
| weak Hashed (e.g. SHA-256, MD5) | A one-way fingerprint of the password. | Identical passwords have identical hashes, precomputed rainbow tables crack common ones instantly, and GPUs try billions of guesses per second. |
| better Salted hash | Hash of a unique random salt + password, plus the salt. | Identical passwords look different and rainbow tables are useless, but fast hashes still allow billions of guesses per second. |
| recommended Slow, salted password hash | Argon2id, scrypt, bcrypt or PBKDF2 output, with salt and cost settings. | Each guess is deliberately expensive (and memory-hungry, for Argon2 and scrypt), cutting the attacker's speed by a factor of millions. |
Steal the database
Four users, two of whom chose the same password. Switch between storage methods to see what an attacker would find in the stolen table.
Rainbow tables: why salting matters
For unsalted hashes, attackers don't even need to guess. They download huge precomputed tables mapping hashes back to passwords (rainbow tables are a space-efficient version of this) and simply look each stolen hash up.
This mini table holds the SHA-256 hashes of common passwords. Real tables hold billions.
Slow on purpose: work factors
General-purpose hashes like SHA-256 are designed to be fast, which is great for checking files but terrible for passwords. Password hashing functions add a cost (iterations, and for Argon2 and scrypt, memory) so each guess takes real time. A user signing in won't notice 100 milliseconds. An attacker making a billion guesses certainly will.
OWASP currently recommends Argon2id where available; for PBKDF2-HMAC-SHA256 it suggests about 600,000 iterations. A real attacker's GPU rig is much faster than your browser, but the cost scales the same way.
Lessons from real breaches
- 2009 · RockYou
32 million passwords stored in plaintext. The leaked list became the standard wordlist for password cracking, and is still in use today. - 2012 · LinkedIn
Passwords stored as unsalted SHA-1. Most were cracked within days. The full set of 117 million resurfaced in 2016. - 2013 · Adobe
153 million passwords encrypted with 3DES in ECB mode (see the ECB penguin in the crypto primer), with password hints stored in plaintext. Identical passwords gave identical ciphertext, so the hints effectively solved them. - 2022 · LastPass
Encrypted customer vaults stolen. Each vault is protected by the user's master password through PBKDF2, so the risk depends on how strong each master password and iteration count is.