Skip to main content

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

Password input
Add salt
Stretching (repeated hash computation)
Store the hash value in the DB

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

Salt

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.

Pepper

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.

1. Argon2id
2. scrypt
3. bcrypt
4. PBKDF2

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