Skip to content
Ameen Abozaid
JNR-037

Password security

  • 5 Lessons
  • 2 h practice (estimate)
On this page 8 topics

Overview

Topics

  • Password hashing
  • salts
  • adaptive algorithms
  • account lockout

Learn first

2 h of practice (estimate)

Learning outcomes

  1. Explain why passwords are hashed (not encrypted) and why salts and slow algorithms matter.
  2. Store passwords with PasswordEncoder (bcrypt or Argon2) and support future algorithm upgrades.
  3. Implement registration with sensible password rules (length over complexity, breached-password check concept).
  4. Implement rate limiting or lockout for failed logins and explain the denial-of-service trade-off.

Lessons

  1. 01How passwords get stolen
  2. 02Hashing, salting, and slow hashes
  3. 03PasswordEncoder and upgrades
  4. 04Brute force, lockout, and throttling
  5. 05Demo: registration with password hashing and throttling

Lab and exercises

Lab

JNR-037-LAB1 · Registration

Outcomes: 1–4 · Time: ~2 h Implement registration with hashed passwords; throttle after 5 failed logins per account and IP. Acceptance: no plaintext or reversible password anywhere, including logs.

Exercises (assessment: review a flawed registration flow)

IDOutcomeTask
JNR-037-EX011Explain in three sentences why a database stores hashes, not encrypted passwords.
JNR-037-EX021Explain what a salt prevents and why MD5 is wrong for passwords.
JNR-037-EX032Configure a delegating PasswordEncoder bean and encode and match one password in a test.
JNR-037-EX042Describe how you would move from bcrypt to Argon2 without forcing a password reset.
JNR-037-EX053Write validation for registration: email format, password length 12 to 128, no composition rules.
JNR-037-EX064Implement a failed-login counter and write a test that the sixth attempt gets 429.
JNR-037-EX074Review a flawed flow (MD5 hashes, "email not found" message, password in logs) and list every flaw.
Show solutions
  • EX01 Hashes are one-way, so a stolen database does not reveal passwords; encrypted passwords can be decrypted if the key leaks.
  • EX02 A salt makes equal passwords hash differently and defeats precomputed tables. MD5 is fast and broken for this use, so guessing is cheap.
  • EX03 assertTrue(encoder.matches("pw", encoder.encode("pw"))) and assertNotEquals(encode("pw"), encode("pw")).
  • EX04 Use the delegating encoder with the new default; old {bcrypt} hashes still match; re-encode on successful login when upgradeEncoding is true.
  • EX05 @Email, @Size(min = 12, max = 128) on the password; reject known-breached passwords where a list is available (concept).
  • EX06 Keep a map of key (account + IP) to counters and a lock-until time; return 429 after five failures; reset on success.
  • EX07 MD5 is fast; "email not found" leaks which emails exist; password in logs is plaintext exposure. Fix: delegating encoder, generic message, mask logs.

Quiz

Outcomes: O1 hashing, salts, slow algorithms · O2 PasswordEncoder and upgrades · O3 registration rules · O4 throttling and lockout.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1Passwords should be stored:O1
  2. 2A salt is:O1
  3. 3Why not SHA-256 for passwords?O1
  4. 4PasswordEncoder.matches(raw, stored):O2
  5. 5The {bcrypt} prefix in a delegating encoder allows:O2
  6. 6A sensible password rule is:O3
  7. 7On failed login, the message should be:O3
  8. 8A permanent lockout after 5 failures risks:O4
  9. 9A good status for too many attempts is:O4
  10. 10Throttling is best keyed by:O4

Practical part

Seven exercises JNR-037-EX01 to EX07 plus the lab; the flawed-flow review is the assessment. Pass: at least six exercises correct, all flaws in EX07 found, and no plaintext password in the database or logs.

Common mistakes

MD5/SHA-256 for passwords; revealing whether an email exists.

Assessment

Review a flawed registration flow.

Career relevance

Identity architecture (ARC-017).

Type to search levels, phases, modules and lessons.