Password Hashing - Irreversible Storage for Credentials
About 2 min read
Password hashing is a technique that converts a user's password into an irreversible fixed-length value before storing it in a database. Even if the database is leaked, the original password cannot be computed back from the hash value, so the damage can be limited. Storing passwords in plaintext is a serious design flaw.
The Dangers of Plaintext Storage
The danger of storing passwords in plaintext (as the raw string) has been shown by past incidents. In the 2009 RockYou breach, about 32 million passwords were leaked in plaintext. Once attackers obtained the database, they had every user's password. We explain how to respond to a data leak in detail in the data breach response guide.
An Overview of Password Hashing
Why General-Purpose Hashes Are Unsuitable for Passwords
SHA-256 and SHA-512 are cryptographically secure hash functions, but they are not suitable for hashing passwords. The reason is that they are "too fast." SHA-256 is fast to compute, and using a GPU makes it even faster. For an attacker, this means they can try an enormous number of password candidates in a short time. Password-specific hash functions address this problem by deliberately making the computation slow.
The Roles of Salt and Pepper
A random value that differs for each user is added to the password before it is hashed. Even for the same password, a different salt produces a different hash value, which neutralizes rainbow table attacks. The salt is stored in the database together with the hash value.
It is a secret value shared by all users, stored in a location separate from the database (such as a secrets vault or an HSM). Even if the database is leaked, the hash cannot be recomputed without the pepper, so it functions as an additional layer of defense. However, it increases the complexity of key management.
The Concept of Stretching
Stretching is a technique that deliberately repeats the hash computation to prolong the time a single hash computation takes. For a legitimate user's login, only one computation is needed, so a delay of a few hundred milliseconds is within an acceptable range; but when an attacker tries hundreds of millions of password candidates, the per-attempt delay accumulates and lengthens the attack. Argon2 and bcrypt have a stretching mechanism built in.
Algorithms Recommended by OWASP
As of 2025, OWASP's recommended order of preference is as follows.
OWASP lists Argon2id first and limits bcrypt to legacy systems where Argon2 and scrypt are not available. Choosing the right algorithm reduces the risk of a credential leak. You can learn the basics of encryption in the basics of encryption article.
Examples of Misconceptions
One misconception is that "encryption makes it safe." Encryption is a two-way transformation that can be decrypted with the key, and if the key is leaked, all passwords are exposed at once. OWASP states that, in almost all circumstances, passwords should be hashed (a one-way transformation), not encrypted. The idea that "if you keep the salt secret, a pepper is unnecessary" is also wrong. Because the salt is stored together with the hash value, it is exposed simultaneously when the database is leaked. The pepper becomes an additional layer of defense precisely because it is stored in a location separate from the database. For the full picture of secure password operation, see the secure password management guide.
Was this article helpful?
Related Terms
- 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.
- What Is Two-Factor Authentication (2FA)?Two-factor authentication adds a second verification layer to your login. Compare SMS codes, authenticator apps, and hardware keys for safety.
- PBKDF2 - Password-Based Key DerivationPBKDF2 derives cryptographic keys from passwords and is standardized in NIST SP 800-132. Used in Wi-Fi WPA2, it lacks GPU resistance, so migration to Argon2 or bcrypt is recommended.
- Password Salting - Why Hashing Alone Falls ShortA salt adds unique random data to a password before hashing so identical passwords yield different digests. Learn how salting protects against rainbow table attacks.