Cybersecurity Essentials for Developers · Chapter 2 · ~15 min · Beginner
Passwords, Hashing & Protecting User Data
Learn how production applications store user credentials safely: why plaintext passwords cause catastrophic data leaks, how one-way cryptographic hashing works, and why adding Salt stops rainbow table attacks dead in their tracks.
- Understand why databases must NEVER store plaintext passwords
- Master one-way cryptographic hash functions (SHA-256 vs Bcrypt)
- Learn how attackers use GPU brute-force and Rainbow Tables
- Implement cryptographic Salt to make password storage bulletproof
1The Golden Rule: NEVER Store Plaintext Passwords!
Imagine you build a website and store users in a database table:
⚠️ Catastrophic Anti-Pattern (Plaintext):
id: 1 | email: alice@acme.com | password: "MySecretPassword123"
If a hacker ever penetrates your database through an SQL injection or leaked backup file, they now have every single user's password in plain text!
Because over 70% of people reuse the exact same password across multiple websites, that single leak allows attackers to take over Alice's Gmail, Amazon, and online banking accounts!
What is the catastrophic danger of storing user passwords in plaintext inside a database?
2What is Cryptographic Hashing? The One-Way Blender
Think of a cryptographic hash function like a kitchen blender:
You put a strawberry, banana, and milk into the blender. It turns into a pink smoothie. Given the fruit, making the smoothie is easy and always produces the exact same color. But given the smoothie, you can NEVER un-blend it back into a whole strawberry!
Hashing is a one-way mathematical function:
// Turning text into a hash:
hash("secret123") -> "ef92b778bafe771e89245b89ecbc..."
// Reversing the hash back to text:
IMPOSSIBLE! No formula exists to reverse a cryptographic hash.How Login Verification Works:
- When the user registers, you hash their password and save only the hash in the database.
- When the user logs in later, you take what they typed, hash it, and compare the two hashes!
- If the hashes match, they typed the right password — and your database never knew their real password!
If a website never stores your real password in its database, how does it verify your login?
3Why Simple Hashes Fail: Rainbow Tables
Early systems hashed passwords with fast algorithms like MD5 or SHA-1.
The problem? Modern graphics cards (GPUs) can calculate 50,000,000,000 hashes per second!
Attackers precomputed billions of hashes for common words (like "password", "qwerty", "iloveyou") and stored them in giant lookup databases called Rainbow Tables. When an attacker steals your database, they look up the hash and find the word in 1 second!
What is a 'Rainbow Table' in password cracking?
4The Antidote: Cryptographic Salt & Bcrypt
To defeat rainbow tables completely, engineers add a Salt:
1. Cryptographic Salt
A unique, random 16-character string generated for every user. Instead of hashing "password", you hash "password" + "k8#mZ9!x"!
• Because every user's salt is different, rainbow tables are completely useless!
2. Slow Hashes (Bcrypt / Argon2)
Unlike fast SHA-256 (used for files), password algorithms like Bcrypt and Argon2 are deliberately slowed down to take ~200 milliseconds per check.
• 200ms is imperceptible to a human logging in, but makes an attacker's GPU take 500 years to guess passwords!
5Hands-On: Test Hashing & Salt Live
Type a password below to observe its SHA-256 hash. Toggle "Add Random Salt" to see how the resulting hash changes completely:
Live One-Way Hashing & Salt Simulator
6Chapter Knowledge Challenge
Test your password storage, cryptographic hashing, and rainbow table defense knowledge:
Why is standard SHA-256 without a work factor considered inadequate for password storage in modern production apps?
What attack is completely stopped by generating a unique random Salt for every user's password?
7Recap
- Never store plaintext passwords! A breach exposes users across all sites where they reuse passwords.
- Cryptographic hashing is a one-way mathematical operation; login verification compares hashes, not plaintext.
- Fast algorithms (MD5, SHA-1) are vulnerable to Rainbow Tables and high-speed GPU brute forcing.
- Always add a unique random Salt and use slow hashing algorithms like Bcrypt or Argon2 to protect credentials.
Congratulations on completing Chapter 2! Mark as complete to update your syllabus: