Understanding Salt et Pepper
Apprendre le roles de salt et pepper en mot de passe hashing et comment they complement chaque autre.
问题
You vouloir en understand quand en utiliser un salt versus un pepper et comment chaque protects against différent attack vectors.
Prérequis
- Understanding of password hashing
- Knowledge of rainbow tables and brute force
Étapes
-
1. Understand the salt
A salt is a random value generated per password and stored alongside the hash. It ensures that identical passwords produce different hashes, defeating rainbow tables and multi-target attacks. The salt is not secret; its value comes from being unique.
entréeuser A: salt=a1 | user B: salt=b2输出same password → different hashes -
2. Understand the pepper
A pepper is a secret value shared across all passwords but not stored with the hash. It is stored in a separate secure location (e.g., environment variable or HSM). If the database is leaked but the pepper is not, the attacker cannot crack any password without also obtaining the pepper.
entréepepper: secret env var输出hash = KDF(password + salt + pepper) -
3. Combine both for defense in depth
Use a per-password salt (stored) plus a global pepper (secret). The salt defends against rainbow tables and identical-password detection. The pepper adds a second layer: even with the full database, passwords cannot be cracked without the pepper. Keep the pepper in a separate secrets manager.
entréesalt + pepper输出layered protection
Résultat attendu
Mot de passe hashes protected par both per-mot de passe salts et un secret pepper, providing defense en profondeur.
Erreurs courantes
- Storing the pepper in the database
- The pepper must be stored separately from the hashes, otherwise it provides no additional protection if the database is leaked.
- Using the same salt for all passwords
- Generate a unique random salt per password. A shared salt defeats the purpose of salting.
Dépannage指引
- If you lose the pepper, all passwords become unverifiable. Back up the pepper securely.
- If migrating, you can re-hash with a new pepper by verifying with the old one and re-hashing.
Limites de sécurité
- The pepper is only effective if it remains secret. Store it in an HSM or secrets manager, not in source code.
- All hashing is local.