Skip to content
What is OpenID Connect?
What is OAuth 2.0?
How do websites remember you?
×

How should apps store passwords?

Databases leak. When they do, your password should stay safe. Here's how good apps make that happen.

Tap the right side to continue →

Never store plain text.

If passwords sit in the database as plain text, one leak exposes every account. And many people reuse passwords on other sites.

Hash it instead.

A hash scrambles a password into a fixed string. It only works one way. To check a login, the app hashes what you typed and compares it to the stored hash.

Why not encryption?

Encryption can be undone with a key. If an attacker steals that key, every password opens. Hashing has no key to steal.

Attackers still guess.

They hash huge lists of common and leaked passwords, then look for a match. Weak passwords fall fast.

Fast hashes help attackers.

Hashes like SHA-256 were built for speed. That lets attackers test guesses very quickly on graphics cards. Password hashing should be slow on purpose.

Add a salt.

A salt is random data added to each password before hashing. Two people with the same password get different hashes, so attackers must crack each one separately. Most libraries add the salt for you.

A pepper adds one more layer.

A pepper is a secret shared by all passwords, kept outside the database in a vault. If only the database leaks, attackers are still missing a piece. It's an extra layer, not a replacement for salt.

Set the work factor.

The work factor decides how slow each hash is. Push it as high as your server allows. But keep each login under one second, or a flood of logins could overload your server.

Pick the right algorithm.

Use Argon2id first. If you can't, use scrypt. Keep bcrypt for older systems. Use PBKDF2 when rules require FIPS compliance.

For developers

Minimum settings from OWASP.

Argon2id: 19 MiB of memory, 2 iterations, and parallelism of 1. PBKDF2 with SHA-256: 600,000 iterations. bcrypt: a work factor of 10 or more, with passwords capped at 72 bytes.

Upgrade old hashes.

Stuck with MD5 or SHA-1? Rehash each password with a modern algorithm the next time its user logs in. Store the algorithm and settings with each hash, so you can upgrade again later.

Quick check

Tap your answer.

Should an app encrypt passwords so it can recover them later?

Two users pick the same password. With salt, do their hashes match?

Which is the best hash for a new app?

Let's recap.

Hash, never encrypt.

One-way, salted, and slow on purpose.

Use Argon2id first.

Tune it so each login stays under one second.

Upgrade old hashes at the next login.

Next short →

Source: OWASP Password Storage Cheat Sheet.

What is MFA?
Authn vs. Authz
×