Reading — step 1 of 5
Read
~1 min readWhy Passwords Need Hashing
Salts
A salt is a random value mixed into the hash:
hashed = hash(salt || password)
Why? Without salt:
- Two users with the same password have the same hash.
- Attackers can precompute hashes of common passwords (rainbow tables).
- One leak compromises every "password123" account immediately.
With salt:
- Each user's hash is different even for the same password.
- Attackers must brute-force EACH ACCOUNT individually — 100M users = 100M separate attacks.
Salt requirements:
- Random (use CSPRNG, not Math.random)
- Unique per password (NOT a global salt)
- Stored alongside the hash (not secret — just unique)
- At least 16 bytes
Storage format (typical):
$2b$12$abc...salt22chars$hashOfPassword31chars
| | |---salt---||---hash---|
alg cost
bcrypt encodes everything in this format. argon2 is similar with more fields.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…