Task 1 of 5

Passwords & How They're Stored

When someone creates an account on a website, what does the server actually store? The answer is not the password itself — and understanding why is foundational to web security.

What is hashing?

A hash function is a mathematical operation that takes any input — a word, a password, an entire file — and produces a fixed-length string of random-looking characters. It works like a one-way process: the input goes in, a scrambled output comes out, and there is no way to reverse the output back to the original input.

WHAT HASHING LOOKS LIKE
Input:
hunter2
MD5 hash:
2ab96390c7dbe3439de74d0c9b0b1767
SHA-256 hash:
f52fbd32b2b3b86ff88ef6c490628285f482af15ddcb29541f94bcf526a3f6c7
bcrypt hash:
$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewYpfQN5jX8YqKoG
All three represent the same password "hunter2" — but the algorithm is different. Notice they're all different lengths and look completely different. None of them can be reversed back to "hunter2".

Two important properties of hash functions:

  • One-way — you can turn a password into a hash, but you cannot turn a hash back into the password. There's no "decrypt" button.
  • Deterministic — the same input always produces the same output. "hunter2" will always produce that same MD5 hash, on any computer, anywhere in the world.

MD5 and SHA-256 — common hash functions

MD5 was invented in 1991. It was used everywhere — file verification, passwords, certificates. The problem: it's extremely fast. A modern GPU can compute billions of MD5 hashes per second. For files, fast is fine. For passwords, fast is a disaster — an attacker can try every possible combination at incredible speed.

SHA-256 is newer and more secure, but it's still a general-purpose hash function. It's still too fast for passwords. It's the right choice for verifying file integrity (e.g. checking a download hasn't been tampered with), but not for storing passwords.

Rainbow tables — how attackers crack hashes

If MD5("hunter2") always equals the same hash, an attacker can just build a massive pre-computed table: a list of millions of common passwords and their MD5 hashes. This is called a rainbow table. When they steal a database of MD5 hashes, they look each one up in their table. If the hash matches, they instantly know the password — no guessing required.

HOW A RAINBOW TABLE WORKS
ATTACKER'S TABLE
password123482c811d...
hunter22ab96390...
letmein0d107d09...
... millions more ...
STOLEN DATABASE
sarah: 2ab96390...
Look up hash → found!
Sarah's password = hunter2

Salting — the fix for rainbow tables

A salt is a random string that's generated for each user and added to their password before hashing. So instead of hashing "hunter2", the server hashes "hunter2xK9#mQ" (where xK9#mQ is Sarah's unique random salt).

Now even if two users have the same password, they get different hashes. And the attacker's pre-built rainbow table is useless — they'd have to rebuild it for every possible salt, which is computationally impossible.

bcrypt — the right tool for passwords

bcrypt was designed specifically for storing passwords. Unlike MD5 or SHA-256, it's intentionally slow — each hash takes about 0.1 to 1 second to compute. It also has a "cost factor" you can increase as computers get faster, to keep it slow. It includes the salt built-in. This is why you see it everywhere in secure applications.

HOW LOGIN ACTUALLY WORKS
1 You type your password: hunter2
2 Server fetches your stored hash from the database
3 Server hashes "hunter2" using the same algorithm + your stored salt
4 If the two hashes match → login succeeds. If not → wrong password.
5 The server never decrypts anything. There is nothing to decrypt.

A practical indicator: if a website's "forgot password" feature emails the actual password (not a reset link), the password is stored in plaintext. The entire user database is exposed in any breach.

1

A site sends you your password in a "forgot password" email (not a reset link). What does this tell you?

2

What is the purpose of a "salt" in password hashing?

Answer all 2 questions to continue