Backend & Node.js · APIs, data and failure

How should you store passwords securely?

Mediumpassword hashingsecurityargon2Updated Oct 2026
Quiz this track

Short answer

Store a salted, slow password hash from bcrypt, scrypt or Argon2id. Never store plaintext or reversible encryption, and tune the cost so one hash takes a deliberate fraction of a second.

Passwords need a one-way function that is expensive to brute force. A general-purpose hash such as SHA-256 is too fast; attackers can test billions of candidates per second. Password hashing algorithms add a salt and a configurable work factor.

js
import { hash, verify } from "@node-rs/argon2";

const digest = await hash(password, {
  memoryCost: 19456,
  timeCost: 2,
  parallelism: 1,
});

const valid = await verify(digest, password);
The salt and parameters are encoded in the digest, so verification does not need a separate salt column.

The rules

  • Use a unique random salt per password, generated by the library
  • Use Argon2id, scrypt or bcrypt; never MD5, SHA-1 or plain SHA-256
  • Tune cost against your hardware and measure login latency
  • Compare with a constant-time verify function from the library
  • Rehash on successful login when you raise the cost parameters
  • Rate limit login attempts and add breached-password checks

bcrypt has a 72-byte input limit and truncates longer passwords silently or throws depending on the implementation. Argon2id is the modern default and lets you tune memory separately from CPU. A pepper, stored outside the database, adds defense in depth but complicates rotation.

Never log passwords or password reset tokens. Reset tokens should be single-use, high-entropy and expire quickly, just like session credentials.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why is SHA-256 unsuitable for passwords?
  2. 2What is the difference between a salt and a pepper?
  3. 3Why does bcrypt have a 72-byte limit?
  4. 4When should you rehash a password?

Say it in the interview

I store passwords with a slow, salted hash such as Argon2id or bcrypt, never with plaintext or reversible encryption. The algorithm's cost is tuned so verification takes a deliberate fraction of a second, and I rehash on login when raising parameters. I also rate limit attempts and check for breached passwords. General-purpose hashes are too fast to resist offline cracking.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Backend & Node.js mock interview and get scored feedback on depth, clarity and confidence.