Security Playbook
11 · Authentication & sessionsOWASP A04:20257 min read

Storing passwords: hashing, salts and slow on purpose

Assume your database will leak one day. What decides whether that's an embarrassment or a disaster is how you stored the passwords. Why fast hashes are the wrong tool and what to use instead.

In one sentence

Never store passwords, store slow, salted hashes made with Argon2id or bcrypt. MD5 and SHA-256 are built to be fast, and fast is exactly what an attacker with GPUs wants.

The idea

A hash is a one-way function: easy to compute, impossible to reverse. But attackers don't reverse hashes; they guess passwords, hash each guess and compare. The only thing that matters is how many guesses per second they can make.

How long to crack this password?
Stored as
Attacker
instantly

⚠ In every breach wordlist: cracked instantly, whatever the hash.

Character set
95
Length
11
Combinations
10^21
Time (brute force)
instantly
Estimates for a full brute-force search; real attackers try wordlists and patterns first, so human-chosen passwords fall much faster. Slow hashes (bcrypt, Argon2id) turn seconds into centuries.
Type any password; it never leaves your browser. Change how it's stored and who's attacking.

What good storage looks like

MethodVerdictWhy
Plain text / encryptionNeverOne leaked key or query reveals every password
MD5, SHA-1, SHA-256NoBillions of guesses per second on one GPU
SHA-256 + saltStill noSalt stops precomputed tables but not fast guessing
bcrypt (cost ≥ 12)GoodDeliberately slow; widely supported
Argon2idBest defaultSlow and memory-hard, so GPUs lose most of their advantage
import { hash, verify } from "@node-rs/argon2";

const stored = await hash(password);           // salt + params included
const ok = await verify(stored, attempt);      // constant-time compare
// stored looks like: $argon2id$v=19$m=19456,t=2,p=1$<salt>$<hash>

A salt is a random value stored next to each hash, so two users with the same password get different hashes and attackers can't crack everyone at once. Modern libraries add it for you.

Beyond the hash

  • Check new passwords against breach lists (e.g. the k-anonymity Pwned Passwords API) and reject the known ones.
  • Length beats complexity rules: allow long passphrases and paste from password managers; drop forced symbols and periodic resets.
  • Rehash on login when you raise the cost or switch algorithms.
  • A pepper (a secret kept outside the database) adds a layer if only the DB leaks.

Key takeaways

  • 01Store salted, slow hashes: Argon2id or bcrypt, never MD5/SHA.
  • 02Attackers guess; slow hashes make every guess expensive.
  • 03Reject breached passwords and allow long passphrases.
  • 04Passkeys avoid storing a crackable secret at all.

Check your understanding

1 of 3

How should passwords be stored?

Related concepts