Cyber Trainer Passwords & Auth
Passwords & Auth · Chapter 03

How passwords are stored

A well-run website never knows your password. It stores something it can check your password against. How it does that decides what happens when its database is stolen, and databases do get stolen.

From worst to best

MethodWhat's storedIf the database is stolen…
never PlaintextThe password itself.Every password is exposed immediately, and reused passwords unlock other sites.
never EncryptedThe 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 hashHash 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 hashArgon2id, 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.
Salt and pepperA salt is random, unique per user and stored next to the hash. It isn't secret; its job is to make every hash different. A pepper is an extra secret value added to every password and kept outside the database (for example in an HSM or secrets vault), so a database-only leak isn't enough to start cracking.

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.

What the attacker sees

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.

Look up a hash

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.

Measure it on your device
Press "Time one hash".

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

Windows passwordsWindows stores local and domain passwords as NT hashes: unsalted MD4. They're fast to crack, and in a Windows domain the hash itself can be used to sign in ("pass-the-hash") without ever cracking it. Long passwords, Credential Guard and limiting admin rights are the defences.

Knowledge check