Station PASS said that sites should store a fingerprint of your password, not the password. This lesson shows how that is done well, and why two extra ideas, salt and slow hashing, matter so much.
Never store the password
When you sign up, the site stores a fingerprint of your password. When you sign in, it makes a fingerprint of what you typed and compares. It never needs the password itself, so a stolen database does not hand over passwords directly. But plain fingerprints have two weaknesses, which the figure shows.
| User | Password stored |
|---|---|
| asha | Cricket@123 |
| ravi | Cricket@123 |
| meera | tiger lamp river cloud mango bench |
The worst way to store passwords is as they are. One leak of this table hands every password to the attacker, and people who reused them lose other accounts too.
Salt
With salt, two people with the same password get different fingerprints, and an attacker’s ready-made tables of common passwords no longer match anything.
Slow on purpose
SHA-256 is designed to be fast, which is good for checking files and bad for passwords: attackers can try billions of guesses a second. Password hashes such as Argon2, scrypt and bcrypt are slow on purpose and can be made to use lots of memory. A user waits a tiny fraction of a second once; an attacker must wait that long for every guess. OWASP’s current advice is to use Argon2id where possible.
Lab: fingerprints and salt
Compare the fingerprints of two texts that differ by one character. Then give two users the same made-up password and see what salt does. Never type a real password.
1. Change one character
SHA-256 of A a4c3998d f3ff81a6 ef9aa9d4 7acf0646 d71b4a34 faf5e442 725945fe f9e0f0c1
SHA-256 of B dab2f3ab 610dabd5 41758ba3 a662a98b ea9133c6 d8e0ee70 9f49ec03 495284c5
60 of the 64 characters differ. Any change to the text gives a completely different fingerprint.
2. Two users, the same password
| User | Salt | Stored fingerprint (first 16 characters) |
|---|---|---|
| asha | none | 7e9d17e3 0ef2921f … |
| ravi | none | 7e9d17e3 0ef2921f … |
Without salt, both users get the same fingerprint. An attacker who works out one password knows both, and can spot every user with this password.
HASH-3 counts as completed once you step through the figure to its last step.