Course contentsShow
← Software Engineering
Lesson 1001 of 1,93331. Authentication and AuthorizationFree lesson

Salt: Preventing Rainbow Table Attacks

Understanding salts, how they defeat precomputed hash attacks, and why each password needs a unique salt.

Salt: Preventing Rainbow Table Attacks

What you'll learn: How adding a unique random value to each password before hashing defeats precomputed hash lookup attacks.

The Problem with Plain Hashing

Even when passwords are hashed (as taught in the previous lesson), attackers can still use rainbow tables—massive precomputed databases mapping common passwords to their hash values. If two users have the password "password123", they'll have identical hashes, making bulk cracking efficient.

What is a Salt?

A salt is a unique, random value generated for each user that gets combined with their password before hashing. Think of it like adding a unique secret ingredient to each person's recipe—even if two people start with the same base ingredients (password), their final dishes (hashes) will be completely different.

User A: hash("password123" + "x7f9k2m") → hash₁
User B: hash("password123" + "q3n8p1z") → hash₂

Even though both users chose the same weak password, their stored hashes are entirely different.

Why Salts Defeat Rainbow Tables

Rainbow tables work because they precompute millions of password-to-hash mappings. But with salts:

  1. Every password needs a unique precomputed table (one per salt value)
  2. Attackers would need to compute billions of rainbow tables
  3. This becomes computationally infeasible

The salt is stored alongside the hashed password in your database—it doesn't need to be secret, just unique and unpredictable.

Critical Requirements

  • Each password must have its own unique salt (never reuse)
  • Salts should be cryptographically random
  • Salts should be long enough (at least 16 bytes/128 bits)
  • Generate a new salt whenever a password changes

Key Takeaway: Salts are unique random values added to passwords before hashing, making precomputed rainbow table attacks impossible by forcing attackers to crack each password individually.