Password hashing

Does a website actually know your password?

Demo 6 of 7Reel"Alam ba talaga ng Facebook ang password mo?"

Try it

Type a pretend password and see what a careful website keeps instead of it.

crypto.subtle, in this tab
11 characters

Make one up. It never leaves this tab, but a real password has no place in a demo.

1. Plain hash

SHA-256

Working

The same password gives the same hash every time, on every site that does this. If a list of these leaks, anyone with a table of common passwords and their hashes can read the common ones straight back.

2. Add a salt

SHA-256 of salt + password
  • Anasalt …

    Working

  • Bensalt …

    Working

A salt is random bytes added to the password before hashing. Each person gets their own, stored next to the hash. Same password, different hashes, so a leak no longer shows who shares one.

3. Make it slow

PBKDF2, 600,000 rounds

Hashing 600,000 times

Plain SHA-256

…

PBKDF2, 600,000 rounds

…

…

slower than plain SHA-256, on this device

Real sites use bcrypt, scrypt or Argon2. PBKDF2 is the one your browser has built in, and 600,000 rounds is what OWASP recommends for it.

What just happened

A careful site never stores your password. It stores a hash, a scrambled fingerprint of it. When you log in, it hashes what you typed and compares the two fingerprints.

A plain hash isn't enough, because the same password always gives the same hash. A salt, random bytes added for each user, makes two people with the same password end up with different hashes.

Good password hashes are slow on purpose. A few milliseconds is nothing when you log in, but it turns guessing billions of passwords into years of work.

Where you've seen it

  • A "Forgot password" email that makes you set a new password instead of sending the old one, because the site doesn't have it

Keep going