Hash Function Applications: Password Storage
You'll learn how hash functions enable secure password storage and why raw hashing alone isn't enough.
The Core Idea
When you create an account, the website shouldn't store your actual password—if hackers breach the database, they'd have everyone's passwords! Instead, systems apply a cryptographic hash function to your password and store only the hash. When you log in, they hash what you typed and compare it to the stored hash. If they match, you're in.
Think of it like a fingerprint: the system can verify it's you without keeping a photo of your actual face.
Why Raw Hashing Isn't Enough
If a site just stores hash(password), attackers can use rainbow tables—precomputed lists of hashes for common passwords. Type "password123" into MD5? Always get 482c811da5d5b4bc6d497ffa98491e38. Attackers hash millions of common passwords once, then instantly crack any matching hash in the stolen database.
Salting: Adding Uniqueness
A salt is a random string added to each password before hashing: hash(password + salt). Each user gets a unique salt (stored alongside their hash). Now identical passwords produce different hashes, rendering rainbow tables useless.
Key Stretching: Slowing Down Attacks
Even with salts, fast hash functions like SHA-2 let attackers try billions of guesses per second. Key stretching (or key derivation functions like PBKDF2, bcrypt, or Argon2) intentionally slow down hashing by applying it thousands of times. Your login takes 0.1 seconds longer—no big deal. But an attacker's brute-force attack becomes millions of times slower.
Key Takeaway:
Secure password storage requires hashing with unique salts per user and key stretching algorithms to resist rainbow table and brute-force attacks.