Authentication and authorization · core
Storing passwords: hashing with Argon2id or bcrypt
Never store passwords or encrypt them; store a slow, salted hash (Argon2id first choice, scrypt or bcrypt otherwise) and compare by hashing the login attempt with the same salt and settings.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Hashing is one-way; encryption is reversible (if the key leaks, every password leaks). Passwords are hashed.
- Fast hashes (MD5, SHA-1, SHA-256) are wrong for passwords: attackers test billions of guesses per second. Use a deliberately slow, memory-hard function.
- OWASP minimums: Argon2id with 19 MiB memory, 2 iterations, parallelism 1; scrypt N=2^17, r=8, p=1; bcrypt work factor at least 10 (legacy) and a 72-byte input limit; PBKDF2-HMAC-SHA256 with 600,000 iterations when FIPS is required.
- A unique random salt per password stops rainbow tables and makes equal passwords hash differently; libraries generate and store it in the hash string (PHC format).
- A pepper (a secret kept outside the DB, e.g. in a secrets manager) adds defence in depth.
- Verify with the library's verify function (constant-time comparison). Upgrade old hashes when the user next logs in.
- Also: rate-limit login attempts, check new passwords against breached-password lists, and support MFA/passkeys.
- In Node, bcrypt/argon2 hashing runs on the libuv thread pool, so a login burst can slow other pool work.
The red pen
Common traps: mistake → fix
Mistake: SHA-256 with a salt is good enough
Fix: it is far too fast; use Argon2id, scrypt or bcrypt.
Mistake: Encrypt passwords so support can read them
Fix: nobody should be able to recover a password; use reset flows.
Mistake: Compare hashes with ===
Fix: use the library's verify or crypto.timingSafeEqual.
Easy to hard
Questions interviewers ask, easy to hard
- How do you store user passwords?
- Why not SHA-256? What is a salt? What is a pepper?
- bcrypt vs Argon2id? What settings?
- How would you migrate 2 million MD5 hashes to Argon2id?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.