C

Cryptography › Module 1 › Lesson 3

BeginnerModule 1Lesson 3/5

Password Hashing & Salting

Store passwords with salts and slow hashes so stolen databases are harder to crack

15 min+48 XP3 quiz
Module progress3 of 5
Character chain · Passphrase · Vault lock unlocked

Opening

Databases leak. Plan for that day.

If an app stores passwords as plain SHA-256 of the password alone, attackers with a stolen database can try billions of guesses offline—especially against common passwords. Salting and slow password hashes raise the cost of every guess.

1. Why Raw SHA-256 Is Not Enough for Passwords

General-purpose hashes like SHA-256 are fast by design. Attackers love speed: GPUs can try enormous password lists quickly. Password hashing algorithms (bcrypt, scrypt, Argon2, PBKDF2) are intentionally slow and/or memory-hard so offline cracking hurts.

2. What a Salt Does

  • Unique per user

    Same password → different stored hash for Alice and Bob.

  • Breaks rainbow tables

    Precomputed “password → hash” tables stop working across users.

  • Stored beside the hash

    Salts are not secret like keys; they just must be unique and random.

Conceptual salted hash (demo only — use bcrypt/Argon2 in real apps)import hashlib, os password = b"correct-horse" salt = os.urandom(16) digest = hashlib.sha256(salt + password).hexdigest() print(salt.hex(), digest)

import hashlib, os
password = b"correct-horse"
salt = os.urandom(16)
digest = hashlib.sha256(salt + password).hexdigest()
print(salt.hex(), digest)

Use a library, not a blog snippet

In production, call a vetted password hasher (e.g., Argon2id / bcrypt) via your language’s standard security library. Do not invent your own.

Knowledge Check

1

A salt’s main job for password storage is to:

Multiple choice

Knowledge Check

2

True or False: Fast general hashes alone are ideal for storing passwords.

True or False

Knowledge Check

3

Modern password storage should prefer:

Multiple choice

← Previous

Answer all 3 knowledge checks to continue. (0/3 answered)