Authentication Fundamentals and Password Storage

Understand identity, credentials and password hashing, and implement signup, login, reset and email verification safely.

Intermediate · about 5 hours · difficulty 3/5

Learn first: Error Handling, Validation and API Hardening, Relational Data Modelling in PostgreSQL

Authentication answers "who are you?". Authorization answers "what may you do?". Mixing them up causes many real breaches.

Passwords done right

  • Never store passwords in plain text or with fast hashes like MD5 or SHA-256.
  • Use a slow, salted algorithm built for passwords: argon2id (preferred) or bcrypt.
  • Enforce a sensible minimum length, allow long passphrases, and check against known breached passwords if you can.

The flows you must build

  • Signup with email verification (a signed, expiring link or an OTP).
  • Login with the same generic error for wrong email or wrong password, so attackers cannot discover registered emails.
  • Password reset with single-use, short-lived tokens stored hashed in the database.
  • Rate limiting and lockouts on login and OTP endpoints.

Beyond passwords

Magic links, phone OTP (common in Indian apps), passkeys and social login reduce password risk. Multi-factor authentication matters for admin accounts.

Pitfalls

  • Rolling your own crypto or token format.
  • Reset tokens that never expire or can be reused.
  • Logging request bodies that contain passwords or OTPs.

You are ready to move on when you can explain why bcrypt or argon2 beats SHA-256 for passwords and sketch secure signup, login and reset flows end to end.

Key concepts

  • Authentication vs authorization
  • Password hashing: argon2 and bcrypt
  • Signup and email verification
  • Login and generic errors
  • Password reset tokens
  • Rate limiting login and OTP
  • Passkeys and MFA

Mini project

Implement email and password signup, login and password reset in your API with argon2 or bcrypt, hashed single-use reset tokens that expire in 15 minutes, and rate limiting on login.

Check yourself

Why should a login form say 'invalid email or password' instead of 'no account with this email'?

Free resources