Password hashing and salting, explained

Password hashing and salting in plain terms: what a stored hash and a salt are, how a login check uses them, and why a slow hashing function makes a leaked database much harder to crack. For anyone who builds, audits or relies on password-based login.

  1. What it is

    Store a hash, not the password

    OWASP says passwords should never be stored in plain text, and that hashing is a one-way function: it is impossible to "decrypt" a hash and obtain the original value. A salt is a unique, randomly generated string added to each password as part of the hashing process. NIST requires that passwords be salted and hashed using a suitable password hashing scheme, and that both the salt and the resulting hash be stored for each password. The salt is not a secret.

    Source: OWASP Password Storage Cheat Sheet; NIST SP 800-63B-4, Sec. 3.1.1.2

  2. How it works

    Hash it again, then compare

    NIST describes a password hashing scheme as taking a password, a salt and a cost factor as inputs and producing a password hash, with the salt and hash both stored. So at login the system can recompute the hash from what you typed and the stored salt, and compare it with the stored hash. (Neither source writes out these login steps; this is the direct reading of the requirements.) Because each salt is different, OWASP notes, the same password produces different hashes for different users.

    Source: NIST SP 800-63B-4, Sec. 3.1.1.2; OWASP Password Storage Cheat Sheet

  3. Why it matters

    Make every guess expensive

    NIST notes that offline attacks are possible when an attacker obtains hashed passwords through a database breach. OWASP says fast hashing algorithms such as SHA-256 are not suitable for password storage because they allow attackers to perform large numbers of guesses quickly, and that a unique salt prevents the use of precomputed lookup tables like rainbow tables. Slow, memory-hard algorithms make brute-force attacks significantly more difficult, expensive and time-consuming. OWASP recommends Argon2id first, with scrypt, bcrypt and PBKDF2 as alternatives in particular cases. NIST states the purpose of a password hashing scheme as making each password guess more expensive for an attacker who has obtained a hashed password file.

    Source: OWASP Password Storage Cheat Sheet; NIST SP 800-63B-4, Sec. 3.1.1.2

The takeaway: store a hash, not the password. Add a unique salt to each one. And use a slow function, so every guess costs the attacker. Salting does not by itself slow guessing of a single hash; the slow function does that. A separate secret value called a pepper, stored apart from the database, is an extra layer OWASP describes.

More short lessons

ADIR also offers a free external pen test for cloud teams: see the offer.

Transcript

If a database leaks, are your users' passwords safe? It depends entirely on how they were stored. A system shouldn't store your password at all. It stores a hash, a one-way result you can't turn back into the password. Each password also gets a salt: a unique, random value, stored alongside the hash. At login, the system takes what you typed, adds the stored salt, and hashes it. If the result matches the stored hash, you're in. The system never needs your original password. And because every salt is different, two users with the same password get different hashes. Now say the database leaks. A fast hash like SHA-256 lets attackers make huge numbers of guesses. A unique salt defeats precomputed lookup tables, like rainbow tables. And a slow, memory-hard function like Argon2id makes every single guess expensive and time-consuming. So, store a hash, not the password. Add a unique salt to each one. And use a slow function, so every guess costs the attacker.

Narrated with an AI voice.

Next
Next

The cloud shared responsibility model, explained