読み物Application Security · Security Basics

Level: Basic

Passwords, Passkeys, and Multi-Factor Authentication Explained

Modern password rules from NIST SP 800-63-4, how to store passwords safely, why one-time codes can still be phished, and how passkeys fix that.

Edeeson Opina9 min read

A Basic lesson card: lesson 3 of the Security & Privacy series, Passwords, Passkeys, and Multi-Factor Authentication Explained, with the Miso fox thinking.

What you’ll learn

  • Apply NIST SP 800-63B-4 password rules: length, blocklists, no forced rotation
  • Store passwords with a slow, salted hash such as Argon2id
  • Explain the three authentication factors and why MFA helps
  • Explain why passkeys resist phishing and one-time codes don't
On this page
  1. Before you start
  2. Authentication factors
  3. What current password guidance says
  4. Checking against breached passwords
  5. Storing passwords safely
  6. One-time codes and their weakness
  7. Passkeys: phishing-resistant sign-in
  8. Comparing the options
  9. Account recovery is part of authentication
  10. Common mistakes and troubleshooting
  11. Practical exercise: review a sign-in flow
  12. Key takeaways
  13. References
  14. What's next

Signing in is where most account takeovers begin. Attackers rarely break cryptography; they reuse passwords leaked from other sites, trick people into typing them into fake pages, or guess weak ones. This lesson covers what current guidance says about passwords, how to store them so a database leak doesn't expose them, how multi-factor authentication helps, and why passkeys are the first widely available sign-in method that resists phishing by design.

Before you start

You should know what a session cookie does, from lesson 2, How HTTPS, TLS, Cookies, and Browser Security Work. The code examples use Node.js with TypeScript.

Authentication factors

Authentication proves that the person signing in is the account's owner. The evidence comes in three kinds, called factors:

  • Something you know: a password or PIN.
  • Something you have: a phone with an authenticator app, a security key, or a device holding a passkey.
  • Something you are: a fingerprint or face, almost always used to unlock a device or key locally rather than sent to the server.

Multi-factor authentication (MFA) requires two different kinds. Two passwords are still one factor. The point is that an attacker who steals one kind of evidence, such as a leaked password, still lacks the other.

What current password guidance says

The US National Institute of Standards and Technology publishes digital identity guidelines that many organizations worldwide follow. The current edition is NIST SP 800-63-4, finalized in 2025; its volume SP 800-63B-4 covers authenticators. Its password rules surprise people who grew up with "must contain a symbol" policies:

  • When a password is the only factor, require at least 15 characters. When it's used as part of MFA, the minimum is 8.
  • Allow long passwords: at least 64 characters, including spaces and Unicode.
  • Don't impose composition rules such as "one uppercase, one digit, one symbol." They push people toward predictable patterns like Summer2026!.
  • Don't force periodic changes. Require a change only when there is evidence of compromise.
  • Check new passwords against a blocklist of commonly used, expected, and known-compromised passwords.
  • Don't use password hints or security questions such as "your first pet's name."
  • Let people paste passwords and use password managers. A password manager is the easiest way for a person to have a long, unique password for every site.

These are recommendations for building good systems; they become requirements only if a contract, regulator, or your own policy adopts them. OWASP's ASVS 5.0 takes a similar line: it requires at least 8 characters and strongly recommends 15.

Checking against breached passwords

The Have I Been Pwned "Pwned Passwords" service lets you check a password against hundreds of millions of breached ones without sending it. You send only the first five characters of its SHA-1 hash, and compare the returned suffixes locally. This approach is called k-anonymity.

breached-password.tsTypeScript
import { createHash } from "node:crypto";

/** True if the password appears in known breaches. Only a 5-character hash prefix leaves the server. */
export async function isBreachedPassword(password: string): Promise<boolean> {
  const hash = createHash("sha1").update(password, "utf8").digest("hex").toUpperCase();
  const prefix = hash.slice(0, 5);
  const suffix = hash.slice(5);
  const response = await fetch(`https://api.pwnedpasswords.com/range/${prefix}`, {
    headers: { "Add-Padding": "true" },
  });
  if (!response.ok) throw new Error(`Breach check failed: ${response.status}`);
  const lines = (await response.text()).split("\n");
  return lines.some((line) => line.split(":")[0] === suffix && line.split(":")[1]?.trim() !== "0");
}

SHA-1 is fine here because it's only an index for lookup, not how you store the password. Decide in advance what happens if the service is unreachable: most applications fall back to a local list of common passwords rather than blocking sign-up.

Storing passwords safely

Never store passwords in plain text, and never encrypt them so they can be decrypted. Store a password hash: a one-way transformation that you can check a login attempt against but can't reverse. General-purpose hashes like SHA-256 are the wrong tool because they're designed to be fast, and an attacker with a leaked database can try billions of guesses per second on a graphics card.

Use a deliberately slow, salted password hashing function. The OWASP Password Storage Cheat Sheet recommends, in order of preference:

  • Argon2id, for example with 19 MiB of memory, 2 iterations, and a parallelism of 1 as a minimum;
  • scrypt, if Argon2id isn't available;
  • bcrypt, for older systems (note it uses only the first 72 bytes of the password);
  • PBKDF2 with HMAC-SHA-256 and a high iteration count, where a FIPS-validated algorithm is required.

A salt is a random value stored with each hash, so two users with the same password get different hashes and precomputed tables are useless. Modern libraries generate and store the salt for you, inside the hash string.

passwords.tsTypeScript
import argon2 from "argon2";

const options = { type: argon2.argon2id, memoryCost: 19_456, timeCost: 2, parallelism: 1 };

export async function hashPassword(password: string): Promise<string> {
  // The result includes the algorithm, parameters, and a random salt: store it as one string.
  return argon2.hash(password, options);
}

export async function verifyPassword(stored: string, attempt: string): Promise<boolean> {
  return argon2.verify(stored, attempt);
}

export function needsRehash(stored: string): boolean {
  // Raise the cost over time; re-hash at the next successful sign-in.
  return argon2.needsRehash(stored, options);
}

Tune the parameters on your production hardware so one hash takes a noticeable fraction of a second without overloading the server, and combine them with login rate limits so the slow hash can't be used to exhaust your CPU.

One-time codes and their weakness

The most common second factor is a one-time code:

  • SMS codes are better than nothing but weak. Phone numbers can be hijacked through SIM swapping and number porting, and messages can be intercepted. NIST treats SMS and voice codes as a "restricted" authenticator, usable only with extra safeguards and an alternative offered.
  • Authenticator apps generate time-based codes (TOTP, RFC 6238) from a secret shared when the user scans a QR code. They don't depend on the phone network.

Both have the same fundamental weakness: they can be phished. A fake login page can ask for the password and then the code, and relay both to the real site within seconds. People can't reliably tell a perfect copy of a sign-in page from the original, and the code works for whichever site it's typed into.

Passkeys: phishing-resistant sign-in

Passkeys are credentials built on the W3C Web Authentication standard (WebAuthn) and the FIDO2 protocols. When a user creates a passkey, their device generates a key pair. The private key stays on the device (or in the platform's encrypted passkey sync, such as a phone's password manager), and the server stores only the public key.

At sign-in, the server sends a random challenge; the device signs it after the user unlocks it with a fingerprint, face, or PIN. Two properties make this strong:

  • Nothing reusable is sent. The server never holds a secret that can be leaked and replayed elsewhere.
  • The credential is bound to your site. The browser includes the origin in what is signed and only offers a passkey for the site it was created for (its relying party ID). A look-alike phishing domain simply can't get a valid signature.

That binding is what NIST calls phishing resistance. SP 800-63B-4 requires services at its middle assurance level (AAL2) to offer at least one phishing-resistant option, and its highest level (AAL3) to use one with a non-exportable key, which rules out synced passkeys at AAL3 but allows them at AAL2.

In the browser, signing in with a passkey is a single API call. Your server creates the challenge and verifies the response:

passkey-sign-in.tsTypeScript
// Browser side. The options come from your server; the challenge is random, single-use, and short-lived.
const options = await (await fetch("/api/passkeys/sign-in/options", { method: "POST" })).json();
const credential = await navigator.credentials.get({
  publicKey: {
    challenge: base64urlToBuffer(options.challenge),
    rpId: options.rpId, // your registrable domain, for example "shop.test"
    userVerification: "preferred",
    timeout: 60_000,
  },
});
// Send the signed assertion back; the server checks the challenge, origin, RP ID hash, signature, and counter.
await fetch("/api/passkeys/sign-in/verify", { method: "POST", body: JSON.stringify(serialize(credential)) });

Verifying the response by hand is intricate, so use a maintained WebAuthn server library and follow its documentation for checking the origin, the relying party ID, the challenge, and the signature.

Comparing the options

From weakest to strongest against the most common attacks:

  1. Password only: falls to reuse, guessing, and phishing.
  2. Password plus SMS code: stops simple reuse; falls to phishing relays and SIM swapping.
  3. Password plus authenticator app: stops reuse and SIM swapping; still falls to phishing relays.
  4. Passkey or security key: resists reuse, guessing, and phishing, because there is nothing to type and the credential only works on your origin.

For most consumer applications, a sensible plan is: offer passkeys, keep passwords as a fallback with the rules above, offer an authenticator app as a second factor, and require phishing-resistant MFA for administrators.

Account recovery is part of authentication

An account is only as strong as its weakest way back in. If "forgot password" lets anyone with access to a recycled phone number reset an account, the strong sign-in doesn't matter. Send reset links by email with a random, single-use token that expires quickly (for example within an hour), store only a hash of the token, invalidate it after use, and notify the user when the password or MFA settings change. Lesson 9 builds this flow.

Common mistakes and troubleshooting

  • Hashing with SHA-256 or MD5. Fast hashes are the wrong tool. Migrate by re-hashing with Argon2id at the next sign-in.
  • Maximum lengths like 16 characters. They block passphrases and password managers. Allow at least 64.
  • Blocking paste on password fields. It hurts password manager users and doesn't stop attackers.
  • Treating MFA codes as phishing-proof. Only origin-bound methods such as passkeys are.
  • Recovery that bypasses MFA. A support process or SMS reset that skips the second factor undoes it.
  • "Invalid password" for one case and "unknown email" for another. Different messages tell attackers which accounts exist. Use one message for both.

If users report that a passkey "doesn't show up," check that the rpId matches the domain where they created it; a passkey made on one domain won't be offered on a different one.

Practical exercise: review a sign-in flow

On an application you're building or allowed to test:

  1. Find the password hashing code. Note the algorithm and parameters, and compare them with the OWASP recommendations.
  2. Try creating an account with a 70-character passphrase containing spaces. Does it work?
  3. Try the password password1234567. Is it refused as common?
  4. Check whether "forgot password" gives the same response for a registered and an unregistered email.
  5. List the second factors offered, and mark which are phishing-resistant.

Key takeaways

  • NIST SP 800-63B-4: long passwords (15 or more characters as a single factor), no composition rules, no forced rotation, and a blocklist.
  • Store passwords with Argon2id (or scrypt, bcrypt, PBKDF2) and a per-password salt; never with a fast hash.
  • MFA blocks most password-reuse attacks, but one-time codes can still be phished.
  • Passkeys are phishing-resistant because they're bound to your site's origin and nothing reusable is sent.
  • Account recovery must be as strong as sign-in.

References

What's next

Accounts hold personal data, and so do forms, logs, and analytics. Understanding Personal Data, Privacy, and Data Minimization explains what counts as personal data and how collecting less of it makes your application safer.

See every lesson in Security & Privacy: Building Secure Applications