SteelReed

Search

Search posts, questions…

SecurityQuestion 3 / 24

Junior

How should you store passwords, and why not SHA-256 or encryption?

Short answer

Use a slow password hash with a salt and cost parameters: Argon2id by default, bcrypt is still fine, PBKDF2 when you need FIPS. SHA-256/MD5 are too fast (GPUs try billions per second), and encryption is the wrong model because you never need to read the password back.

old hashUser's passwordArgon2idown salt, m, t, pStore hash + saltin DBNext loginmatches: rehash, compareupgradeEncoding: rehash

3 points to say:

  1. A slow, memory-hard algorithm: Argon2id (OWASP suggests m=19 MiB, t=2, p=1); bcrypt cost 10–12, 72-byte input limit.
  2. A unique salt per password (defeats rainbow tables); keep the pepper outside the DB.
  3. DelegatingPasswordEncoder stores an {id} prefix so you can migrate algorithms gradually as users log in again.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.