Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Authentication, Authorization, and Password Storage

โญโญ intermediateโณ 24 min read๐Ÿ“ Lesson 151 of 265

Who are you (authn) vs what may you do (authz) โ€” and why passwords are stored as salted, slow hashes, never plaintext or bare digests.

Two different questions

  • Authentication โ€” who is this requester? (verify a credential: password check, token validation.)
  • Authorization โ€” what is this authenticated identity allowed to do? (roles, ownership checks, least privilege.)

They fail differently: a missing authn check lets strangers in; a missing authz check lets valid users do things they shouldn't (IDOR โ€” acting on someone else's record id). Check both, in that order, at every boundary.

Password storage: salted slow hashes

Databases get dumped. The stored form must be useless to the attacker:

  1. Never plaintext. Anyone with the file knows every password.
  2. Never a bare digest (SHA256(password)): digests are fast โ€” GPUs try billions per second โ€” and identical passwords produce identical hashes (rainbow tables).
  3. Store salt + slow-KDF(password, salt). The salt is random per user, stored in the clear next to the hash; it kills precomputation and makes identical passwords hash differently across users. The KDF is a deliberately slow function โ€” PBKDF2 is in the box:
using var kdf = new Rfc2898DeriveBytes(
    password, salt, iterations: 100_000, HashAlgorithmName.SHA256);
byte[] hash = kdf.GetBytes(32);

Verification recomputes with the stored salt and compares. Per-user salt + slow KDF are the two halves; either one alone is half a defense.

Least privilege and secrets

  • Run with the narrowest rights that work; a compromised component then compromises less. Admin-only operations demand an explicit role check โ€” "the UI hides the button" is not a check.
  • Secrets (connection strings, API keys) live in configuration/environment, referenced by code โ€” never literals in source, and never in logs or exception messages.

โšก Now practice

Ready to Code
Security Practice: Barriers at the BoundaryTurn a string-built query into a parameterized one, confine path resolution, store passwords with PBKDF2 + per-user salt, and keep secrets out of log lines.
4 challenges ยท ยท ~32 min