Password Salting - Why Hashing Alone Falls Short
About 2 min read
A salt is random data added when hashing a password. Since the same password produces a different hash value when the salt differs, salts protect against rainbow table attacks and other precomputation attacks. A salt is generated uniquely for each user and stored together with the hash value.
How Salt Works, with a Numerical Example
When hashing a password, the salt is generated by a cryptographically secure random number generator and combined with the password before being fed into the hash function. For example, adding a 16-byte (128-bit) salt to the password "mypassword" produces a completely different hash value for each user even with the same password. The Argon2 specification (RFC 9106) recommends a 16-byte salt for password hashing, and bcrypt uses a 128-bit salt. As of October 2026, the OWASP Password Storage Cheat Sheet recommends using Argon2id. The salt does not need to be kept secret and is stored in the database together with the hash value.
| User | Salt (16 bytes, first 8 digits) | First 16 digits of the hash |
|---|---|---|
| User A (no salt) | None | 89e01536ac207279... |
| User B (no salt) | None | 89e01536ac207279... |
| User A (with salt) | 8f2b7c1d... | 58ef28c75d1f8e9e... |
| User B (with salt) | 1a4c9e2b... | f8250873b0d4600e... |
The two rows without a salt end up with the same value, and that is exactly why rainbow tables work. The lower two rows, each with a different per-user salt, produce values with nothing in common even though the password is identical.
How to Migrate an Existing System That Has No Salt
When migrating an existing system away from unsalted storage, the stored hash values cannot simply be regenerated. Because a hash cannot be reversed, the service does not hold users' plaintext passwords and therefore has no material at hand from which to compute hashes in the new scheme. Migration therefore proceeds by waiting until a user next logs in and enters the correct password, and then building a new-scheme hash from that value to replace the old record. It is not completed in a single operation; the replacement progresses over time in proportion to how often users log in. Records for users who have not logged in for a long period remain in the old scheme, so decisions such as setting a deadline and requiring a password reset become necessary. Since the old and new schemes coexist in the database during migration, the design also needs a way to tell from the record which scheme a given entry was stored with. Where unsalted storage remains in operation, the time this migration takes is itself a factor that shapes the scale of the damage in the event of a leak.
Why a Salt Is Necessary
Without a salt, all users who use the same password end up with the same hash value. An attacker can use a rainbow table to crack large numbers of passwords at once. To put it concretely, without a salt an attacker can use a single rainbow table against the hash values of all users. However, when a 16-byte salt is used, theoretically 2 to the 128th power of tables would be required, so precomputed tables no longer apply.
Practical Pitfalls
One mistake is using the same salt for all users, which reduces its effectiveness against rainbow tables. Likewise, if the salt is too short, it becomes easier for an attacker to prepare a table for each salt value. Another pitfall is trying to keep the salt "secret" by storing it in a separate location. The purpose of a salt is to ensure uniqueness, not secrecy, so there is no problem storing it in the same database as the hash value.
Was this article helpful?
Related Terms
- Rainbow Table Attacks - Cracking Hashed PasswordsRainbow tables map precomputed hashes to plaintext for instant password lookups. See why salted hashes and modern algorithms render this attack obsolete.
- Cryptographic Hashing - Protecting Stored PasswordsA hash function converts data into a fixed-length digest that cannot be reversed. See how bcrypt, Argon2, and salting secure passwords against cracking.
- bcrypt - Time-Tested Password Hashingbcrypt is a Blowfish-based password hashing function designed in 1999. It offers an adjustable cost factor and automatic salt generation, and OWASP says it should only be used for legacy systems without Argon2 or scrypt.
- Passwordless Authentication - Beyond PasswordsPasswordless authentication eliminates traditional passwords in favor of biometrics, security keys, or magic links. It reduces phishing risk and password fatigue while improving user experience.