LESSON 30 · INTERMEDIATE5 min read

Passwords, MFA, and Secure Authentication

Store passwords safely, design account recovery and rate limits, and choose authentication factors that resist phishing and replay.

OWASP Top 10 · MITRE ATT&CK · NIST CSF 2.0Free to readModule 7 of 14
YOUR NEXT SMALL WINS

By the end, you’ll be able to…

  • Explain salted password hashing and choose an appropriate password hashing function.
  • Apply modern password policy guidance instead of arbitrary complexity rules.
  • Compare MFA methods and recognise phishing-resistant options.
  • Design safe session, recovery, and rate-limiting behaviour.

01Passwords Are Still Here, So Store Them Properly

Passwords remain a common authentication factor, especially for small organisations and consumer services. The server should never store the password itself. It should store a salted hash produced by a deliberately slow password hashing function. A salt is a unique random value per password that prevents attackers from precomputing hashes or seeing that two users chose the same password.

Argon2id is the modern default recommendation, with scrypt and bcrypt as acceptable alternatives depending on platform support. Parameters should be tuned so one hash takes a noticeable but acceptable amount of time on the server, and reviewed as hardware improves. A fast hash such as SHA-256 is not suitable for passwords because attackers can test billions of guesses per second on specialised hardware.

Store the algorithm, parameters, salt, and hash in a self-describing format so future upgrades are possible. When a user logs in, verify with a constant-time comparison. If the parameters are below the current target, rehash the password after a successful login. Never email a password, log it, or include it in analytics.

password_hash.py🐍Python
Ctrl + ↵
Output
Click Run or press Ctrl+Enter
Output will appear here after you run the code.

02Modern Password Policy

Older advice demanded complexity rules and forced periodic rotation. Modern guidance from NIST favours longer passwords, screening against known-breached passwords, and avoiding unnecessary rotation. Forced composition rules often produce predictable substitutions such as Password1! and encourage reuse. Length and uniqueness matter more than a symbol checklist.

Allow password managers and paste. Do not block long passphrases or unusual characters. Set a reasonable maximum length to prevent denial-of-service through extremely expensive hashing, but make it generous. Check new passwords against a breached-password list using a privacy-preserving method where possible. Rate-limit authentication attempts by account and by source, and use progressive delays or temporary locks with a safe recovery path.

Account recovery is part of authentication. A weak recovery flow can bypass a strong password. Avoid security questions based on public facts. Use time-limited, single-use reset tokens sent to a verified channel, invalidate existing sessions after a reset, and notify the account owner. Do not reveal whether an email address is registered through different error messages or response times.

03Multi-Factor Authentication and Passkeys

Multi-factor authentication combines something you know, something you have, or something you are. A password plus a code from an authenticator app is two factors. A password plus a second password is not. SMS codes add a factor but are vulnerable to SIM swapping, interception, and social engineering. They are better than nothing and weaker than phishing-resistant methods.

TOTP codes are generated from a shared secret and the current time. They work offline and are widely supported, but a real-time phishing proxy can relay a code. Push notifications are convenient but can be fatiguing; number matching and device context reduce accidental approval. Passkeys and hardware security keys using WebAuthn/FIDO2 are phishing-resistant because the credential is bound to the origin and the private key never leaves the authenticator.

Deploy MFA where it matters most first: administrators, remote access, email, source control, cloud consoles, and financial systems. Enforce it with a recovery process that is itself protected. Monitor MFA changes, new device enrolments, and repeated denied prompts. An attacker who can register a new factor often does not need the old one.

mfa-strength.txtPlain text
WEAKER  SMS one-time code        interceptable, SIM swap, phishing relay  Email one-time code      depends on email account security  Push notification        convenient; user fatigue and accidental approvalSTRONGER  TOTP authenticator app   offline, phishable by a real-time relay  Passkey / WebAuthn       origin-bound, phishing-resistant, private key stays on device  Hardware security key    origin-bound, portable, high assurance

04Sessions, Tokens, and the Lifecycle of Trust

Authentication proves identity at a moment. Sessions carry that identity across requests. A session identifier is a bearer token: anyone who steals it can often act as the user. Protect it with HTTPS, the Secure and HttpOnly cookie attributes, an appropriate SameSite setting, a reasonable lifetime, and rotation after login or privilege change.

Logout should invalidate the session on the server, not just delete the cookie in the browser. Password changes, MFA changes, and suspected compromise should revoke all active sessions. Idle and absolute timeouts limit the window of stolen-session abuse. For APIs, use short-lived access tokens and rotation-capable refresh tokens, and bind tokens to the intended audience.

Authentication design is full of small decisions that compound. Write the flow down, including failure messages, lockout behaviour, recovery, enrolment, and revocation. Test the unhappy paths: wrong password, expired code, reused reset token, disabled account, changed phone, lost security key. The goal is not to make login difficult. It is to make impersonation difficult without trapping legitimate users.

LET IT CLICK

The ideas worth keeping.

  • Store passwords with a salted, slow password hashing function such as Argon2id.
  • Favour length, breach screening, rate limits, and safe recovery over arbitrary complexity rules.
  • Prefer phishing-resistant MFA for administrators, email, source control, and cloud consoles.
  • Sessions are bearer credentials: protect, rotate, expire, and revoke them.
TURN UNDERSTANDING INTO SOMETHING YOU CAN DO

Make it yours.

Type and test your code right here in the interactive workspace. Run your solution, check the output, and compare with the worked guide when ready.

01

Exercise 1: Review a password policy

A policy requires exactly 8 characters, at least one uppercase, one lowercase, one number, and one symbol, forces a change every 60 days, and blocks paste. Identify four problems and propose replacements.

Explore a worked solution
one_possible_solution.mdCybersecurity
1. Eight characters is too short; require at least 12-16 and allow longer passphrases. 2. Composition rules encourage predictable patterns; prioritise length and screen against breached passwords. 3. Forced 60-day rotation encourages weak incremental changes; rotate only on evidence of compromise or risk. 4. Blocking paste breaks password managers and encourages weaker passwords; allow paste and password managers. Also add rate limiting, MFA, and a safe recovery process.

Modern policy focuses on length, uniqueness, breach screening, and usability. Arbitrary complexity and frequent rotation often reduce real security.

02

Exercise 2: Design a password reset flow

Describe a secure reset flow for a web application, including token generation, delivery, expiry, reuse, session handling, and user enumeration.

Explore a worked solution
one_possible_solution.mdCybersecurity
Generate a cryptographically random, single-use token and store only its hash with the user ID, creation time, expiry, and request context. Deliver the token by email or another verified channel. Expire it after 15-30 minutes and invalidate any previous unused tokens. The reset page must not reveal whether the email exists; always show the same neutral message. On success, verify the token hash, allow one use, set the new password with a strong password hashing function, revoke all existing sessions, and notify the user. Rate-limit requests by account and source, and alert on unusual reset patterns.

A reset token is a temporary credential. It must be random, single-use, short-lived, delivered over a trusted channel, and invalidated after use.

A SMALL QUESTION. A USEFUL NEXT STEP.

What stayed with you?

Check the ideas while they’re fresh. Your answers stay in this page and feedback appears as you go.

A LITTLE ACTIVE RECALL0 / 4 answered
01Why is a salt used when hashing passwords?
02Which authentication method is phishing-resistant by design?
03What should happen to existing sessions after a password reset?
04Why is a different error message for unknown and known accounts a problem?

Keep exploring.

The official references behind this lesson, when you want a second angle or the full details.

One lesson closer.

Reading is a start. Trying it yourself makes the connection.

Completion is saved in this browser. It records reading and hands-on practice progress.