Course contentsShow
← Computer Science
Lesson 2506 of 2,87256. Authentication and AuthorizationFree lesson

Salt: Defending Against Rainbow Tables

What salts are, how they prevent precomputed hash attacks, and proper salt generation.

Salt: Defending Against Rainbow Tables

You'll learn how adding random data to passwords before hashing defeats precomputed attack tables.

What is a Salt?

A salt is a unique, random string added to each password before hashing. Without salts, an attacker who steals your password hash database could use rainbow tables—massive precomputed lists mapping common passwords to their hashes—to instantly crack millions of passwords.

Think of it like adding a random ingredient to every dish you cook. Even if two people order the same meal, each gets a unique version that can't be identified from a generic recipe book.

How Salts Prevent Rainbow Tables

When you hash password123 without a salt, it always produces the same hash: 482c811da5d5b4bc6d497ffa98491e38. An attacker can precompute this once and reuse it forever.

With a salt, each user gets a unique random value:

  • User A: hash("gK7p2X" + "password123") → completely different hash
  • User B: hash("mQ9z4L" + "password123") → another unique hash

Now rainbow tables are useless—attackers would need separate tables for every possible salt, which is computationally impossible with proper salt sizes.

Proper Salt Generation

Requirements for secure salts:

  1. Unique per password: Generate a fresh salt for every user, every time they set a password
  2. Cryptographically random: Use secure random generators, not predictable sequences
  3. Sufficient length: At least 16 bytes (128 bits) to prevent brute-force enumeration
  4. Stored alongside hash: The salt isn't secret—store it plainly in your database next to the hash

The salt is like a unique serial number for each password. Even identical passwords become completely different after salting and hashing.

Key Takeaway: Salts are unique random values added to passwords before hashing, making rainbow table attacks impractical by ensuring every password hash is unique, even for identical passwords.