Course contentsShow
← Security
Lesson 686 of 3,05215. Web Security - Authentication and SessionsFree lesson

Password Salting: Adding Uniqueness to Every Hash

Learn how random salts defeat rainbow tables by making each password hash unique.

Password Salting: Adding Uniqueness to Every Hash

What you'll learn: How adding a random salt to each password makes every hash unique and defeats rainbow table attacks.

The Problem Rainbow Tables Solve (and Create)

You've learned that rainbow tables precompute hashes for millions of common passwords, making simple hashing useless. An attacker can instantly look up 5f4dcc3b5aa765d61d8327deb882cf99 and know it's the hash of "password". But what if we could make the same password produce different hashes for every user?

Enter the Salt

A salt is a random string added to each password before hashing. Think of it like a unique ingredient added to each person's recipe—even if two people use the same base recipe (password), their final dishes (hashes) taste completely different.

When a user creates a password, you:

  1. Generate a random salt (e.g., a long random string)
  2. Combine the password with the salt
  3. Hash the combined string
  4. Store both the hash and the salt in the database

How It Defeats Rainbow Tables

If two users both choose "password123", without salts they'd have identical hashes. With salts:

  • User A: salt: abc123xyz, hash of password123abc123xyz
  • User B: salt: def456uvw, hash of password123def456uvw

Completely different hashes! An attacker would need to build a separate rainbow table for every possible salt value—billions of tables instead of one. This is computationally infeasible.

The salt doesn't need to be secret; it's stored right next to the hash. Its job isn't to hide information—it's to ensure uniqueness.

Key Takeaway: Salting makes each password hash unique by adding random data before hashing, rendering precomputed rainbow tables worthless and forcing attackers to crack each password individually.