What is a salt in cryptography?
Answer
A salt is a random value added to a password before hashing, making each password hash unique even if two users have the same password. Without salting: hash("password123") always produces the same digest — attackers can precompute a rainbow table (mapping passwords to hashes) and look up any hash instantly. With salting: hash("password123" + randomSalt) — the attacker must brute-force each hash individually. Salts must be: (1) Randomly generated per password. (2) Stored alongside the hash (they are not secret — their purpose is uniqueness, not secrecy). (3) Long enough (16+ bytes) to prevent precomputation. Modern password hashing libraries (bcrypt, Argon2) handle salt generation automatically. Never implement your own password hashing — use a vetted library.