SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
  • SSL/TLS
  • Encryption at Rest
  • Secrets Management
  • Password Management
  • RBAC
  • SAML
  • OWASP Top 10 and Common Attacks
  • DDoS Attacks and Defenses
  • Web Application Firewall (WAF)
  • Certificates and PKI
  • Multi-Factor Authentication (MFA)
  • Zero Trust
  • Key Management (KMS)
  • Data Privacy and GDPR Basics
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Operations and Security/Advanced Security

Multi-Factor Authentication (MFA)

Prove who you are with two or more different things: know, have, are. Codes, apps, keys and passkeys.

⏱ 12 min readIntermediateMust KnowInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Multi-factor authentication (MFA) asks for two or more different kinds of proof before it lets you in: something you know (a password), something you have (a phone or key) and something you are (a fingerprint or face).

  • A stolen password alone no longer opens the account. The attacker would also need the second factor.
  • Not all second factors are equal. SMS codes are weakest, app codes are better, and passkeys and security keys are the strongest because they cannot be phished.
  • The attacker often goes for the recovery path or the prompt instead of the factor itself.

02Concept: What is it?

Passwords fail in predictable ways: they are reused, guessed, leaked and phished. MFA means that even when a password is lost, a second proof still stands in the way. The key word is different. Two passwords are not MFA, because one leak can reveal both.

The three factor families
Know
πŸ”‘Password, PINcan be guessed or leaked
Have
πŸ“±Phone, security keycan be lost or stolen
Are
🧬Fingerprint, facecannot be changed if leaked
Strong MFA mixes families. Signals such as location and behaviour are extras, not factors.

Here are the common second steps and what they depend on:

MethodHow it worksMain weakness
SMS or voice codeA code is sent to your phone numberSIM swap, interception, phishing
Email codeA code is sent to your mailboxOnly as safe as the mailbox. Phishable
Authenticator app (TOTP)App and server share a secret and compute a code from the timeCode can be typed into a fake site
Push approvalTap Approve on a promptPrompt bombing (MFA fatigue)
Push + number matchingType the number shown on the login screenLive phishing proxy can relay the number
Security key, passkey (WebAuthn / FIDO2)Device signs a challenge with a private key tied to the siteLost device, so recovery must be safe
🧠Phishing resistance is the big divide
Codes and approvals are things a person hands over, so a convincing fake site can collect them. A passkey signs only for the real site address, so there is nothing to hand over.

03Real-Life Example

🍡The Bank Vault Two Keys
A bank vault needs two keys held by two different people. A thief who steals one key cannot open it. But if the manager can be tricked into handing over their key (a fake phone call), or the spare key is kept in an unlocked drawer (the recovery path), the second lock does not help. MFA is the same: the lock is only as strong as the easiest way past it.
Vault
MFA
Two different keys
Two different factors
Key held by another person
A device you own
A tricked manager
Phishing or prompt bombing
The spare key in a drawer
Weak recovery or backup method
A new key cut for the thief
SIM swap
A key that only fits this vault
A passkey bound to one website

04Why Do We Need It?

πŸ”“Passwords leak
Billions of stolen passwords circulate. MFA makes them far less useful.
πŸ”Password reuse
People reuse passwords, so one small site’s leak threatens a bank.
πŸ›‘οΈBlocks most automated attacks
Credential stuffing and password spraying fail at the second step.
πŸ‘‘Protects powerful accounts
Admin, email and cloud console accounts are the biggest prizes.
πŸ“œRequired by standards
Many security frameworks and cyber insurance policies expect MFA.
πŸͺͺCheap to add
Most identity providers offer it as a switch, not a project.
MFA turns a stolen password from a full break-in into one step of a longer fight.

05Where Do We Use It?

🏒Single sign-on
Do MFA once at the identity provider and protect all apps behind it. See Single Sign-On (SSO).
☁️Cloud consoles
Root and admin cloud accounts should always need MFA, ideally a hardware key.
🏦Banking and payments
Strong customer authentication rules push banks to two factors.
πŸ“§Email and social media
The email account is the recovery path for everything else, so protect it most.
πŸ§‘β€πŸ’»Developer tools
Source code hosts and package registries use MFA to stop supply chain attacks.
πŸ› οΈAdmin and step-up actions
Ask again for risky actions such as changing a bank account or deleting data.

06Types / Parts / How It Works

How an authenticator app code works (TOTP)

When you enrol, the server and your app share a secret (usually via a QR code). After that, both sides compute the same six digits from the secret and the current 30-second time step, using a keyed hash (HMAC, defined in RFC 6238). The code never travels in advance, and an old code stops working when the step moves on. This is why both clocks must be roughly right.

How a passkey works (WebAuthn / FIDO2)

At enrolment your device makes a key pair for this one website and sends only the public key. At login the site sends a random challenge, your device unlocks the private key with a fingerprint, face or PIN, and signs the challenge together with the site's address. A fake site has a different address, so the signature is useless to it. No secret ever crosses the wire.

Why a passkey cannot be phished
🌐Real sitesends a challenge
→↓challenge
πŸ“±Your deviceunlock, then sign (site + challenge)
→↓signature
βœ…Real site checks itwith your public key
The signature includes the real website address, so a look-alike site gets nothing it can reuse.

Strength order (a useful rule of thumb)

LevelMethodsNotes
StrongestPasskeys, FIDO2 security keysPhishing-resistant
GoodAuthenticator app, push with number matchingPhishable by a live proxy
FairPlain push approval, email codesFatigue and mailbox risk
WeakestSMS and voice codesBetter than nothing, but easy to attack
Phishing resistant Phishable Weak

Other pieces

  • Recovery codes: one-time codes saved at enrolment for when the device is lost. Store them offline.
  • Step-up authentication: ask for another factor only for risky actions.
  • Adaptive (risk-based) MFA: skip or add steps based on device, location and behaviour.
  • Attempt limits: rate limit code guesses. A six-digit code has only a million values. See Rate Limiting.
  • Session binding: after MFA, protect the session cookie, because a stolen cookie skips MFA entirely.
VisualizerWhich MFA method survives which attack?Choose a method, then try each attack: stolen password, SIM swap, phishing proxy and push bombing. Then drag the time and clock sliders in part 2 to see how an app code is matched.
Part 1: which method survives which attack?
Second step the user has
What the attacker does
The victim is lured to a look-alike site that passes everything they type to the real site in real time, and keeps the session that results.
πŸ”“
The attacker gets in
User friction:3 / 5
A code is still something a person can type into the wrong site, and it stays valid for about 30 seconds, long enough to relay.
Part 2: how an authenticator app code works
Server computes
418798
time step 20
Phone app shows
418798
time step 20
Code changes in
30 s
Codes match
yes
Both sides start from the same shared secret and the same 30-second time step, so they get the same code without talking to each other.

Illustrative only: the six digits come from a made-up formula, not the real HMAC calculation of RFC 6238. The idea is the same, because the shared secret and the current 30-second step decide the code.

07How to Use It / Steps / Implementation

Rolling out MFA well

  1. 1
    Start with the highest-risk accounts
    Admins, cloud root accounts, email, source code and finance, then everyone.
  2. 2
    Prefer phishing-resistant methods
    Offer passkeys or security keys first. Allow app codes as a fallback, and avoid SMS where you can.
  3. 3
    Add number matching to push
    Show a number on the login screen that the user must type in the prompt, and limit how many prompts can be sent.
  4. 4
    Design recovery carefully
    Give recovery codes, require identity checks for resets, and notify the user. Recovery must not be weaker than login.
  5. 5
    Rate limit and lock
    Limit wrong codes and prompts per account and per source, and alert on bursts.
  6. 6
    Protect the session
    Use short sessions for sensitive apps, bind sessions to the device where possible, and ask again for risky actions.
  7. 7
    Offer more than one method
    Let users enrol a second device or key so a lost phone is not a lockout.
  8. 8
    Watch the metrics
    Track enrolment, failures, fatigue reports and support tickets, and tune.
πŸ’‘Let a provider do it
Use an identity provider or a managed login service instead of writing your own MFA. It handles enrolment, recovery and standards such as WebAuthn. See OpenID Connect (OIDC).
⚠️Store the secrets safely
TOTP secrets are as sensitive as passwords. Store them encrypted with a key from a KMS, and never log them.

08Key Terms to Know

TermMeaning in easy words
MFAMulti-factor authentication: two or more different kinds of proof
2FATwo-factor authentication: MFA with exactly two factors
FactorA kind of proof: something you know, have or are
OTPOne-time password: a code that works once or for a short time
TOTPTime-based OTP: a code computed from a shared secret and the clock (RFC 6238)
WebAuthn / FIDO2Web standards for logging in with public-key credentials on a device or key
PasskeyA WebAuthn credential that can be synced or stored on a device, replacing the password
SIM swapMoving a victim's phone number to the attacker's SIM
MFA fatigueSpamming approval prompts until the user taps Approve
Number matchingThe user types a number from the login screen into the approval prompt
AiTM / phishing proxyA fake site that relays traffic live to the real site and steals the session
Step-up authenticationAsking for another factor before a risky action
Recovery codeA one-time code used when the usual factor is lost

09Pros, Cons and Trade-offs

βœ… Pros
  • Stops most password-only attacks
  • Cheap and widely supported
  • Strong options exist (passkeys)
  • Works with SSO to cover many apps
  • Required or recommended by most standards
⚠️ Cons
  • Adds friction at login
  • Weak methods give false confidence
  • Lost devices create lockouts and support work
  • Recovery paths can be attacked
  • Does not protect a stolen session cookie

Trade-offs

ChoiceWe gainWe lose
SMS codesEveryone has a phone, easy to startWeak against SIM swap and phishing
Authenticator appOffline, no phone networkSetup effort, phishable
Push approvalOne tap, easyFatigue attacks unless number matching
Passkeys / security keysPhishing resistant, fast to useDevice loss handling, rollout effort
Adaptive MFALess friction for safe loginsComplex rules, more things to tune
Ask on every loginHigher assuranceUsers get annoyed and look for shortcuts

10Common Problems and Mistakes

Common mistakes

  1. Leaving SMS as the only choice. It is better than none, but it should not be the end goal.
  2. Weak recovery. A β€œforgot device” link that needs only an email lets attackers skip the factor.
  3. Unlimited prompts. Without limits, push bombing works.
  4. Unlimited code guesses. A six-digit code can be brute-forced if you do not rate limit it.
  5. Trusting the device forever. A β€œremember this browser for ever” cookie that is stolen skips MFA.
  6. Exempting admins or service accounts. They are the most valuable targets.
  7. No backup method. One lost phone locks someone out, and the help desk resets MFA for anyone who asks.

Things to watch

πŸͺSession theft
After MFA the cookie is the key. Short lifetimes and device binding reduce risk.
☎️Help-desk social engineering
Attackers call support and ask to reset MFA. Require strong identity checks.
⏱️Clock drift
TOTP depends on the clock. Allow a small window of adjacent steps.
πŸ”Secrets at rest
TOTP secrets in the database must be encrypted.

11Real-World Examples

πŸ”‘Hardware keys at scale
Google has reported that after requiring security keys for its employees, successful phishing of those accounts stopped.
πŸ“±Passkeys
Apple, Google and Microsoft support passkeys across devices, and many sites now offer them next to passwords.
πŸ””Prompt bombing in the news
Several well-known breaches involved attackers who spammed approval prompts until an employee accepted one.
πŸ“ΆSIM swap fraud
Attackers have used SIM swaps to take over social media and crypto accounts that relied on SMS codes.
🏒SSO providers
Identity providers add number matching, risk checks and WebAuthn as options for every connected app.
πŸ”’Authenticator apps
Apps such as Google Authenticator and Authy follow the TOTP standard, so they work with thousands of sites.
Mini case: the phishing proxy
🎣Fake login pagelogin-shop.example (look-alike)
→↓relays live
🏦Real siteaccepts password + code
→↓session cookie
😈Attacker is inMFA was typed in by the victim
Codes pass through. A passkey would have refused to sign for the fake address.

12Related Topics to Read Next

Password Management→

The first factor: how to store and handle passwords well.

Authentication vs Authorization→

MFA is about proving who you are.

Single Sign-On (SSO)β†’

Do MFA once for many apps.

OpenID Connect (OIDC)β†’

The standard login layer that carries the result of MFA to apps.

Rate Limiting→

Stop code guessing and prompt floods.

Key Management (KMS)β†’

Protect stored TOTP secrets.

Zero Trust→

MFA and device checks on every request, not once.

OWASP Top 10 and Common Attacks→

Authentication failures are a main category.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • βœ”Factors: know, have, are. Use different kinds.
  • βœ”Best: passkeys and security keys (WebAuthn / FIDO2), phishing resistant.
  • βœ”Good: authenticator app (TOTP), push with number matching.
  • βœ”Weak: SMS and email codes, plain push approval.
  • βœ”TOTP: shared secret + 30-second time step, hashed to six digits.
  • βœ”Attacks: phishing proxy, SIM swap, prompt bombing, weak recovery, stolen session.
  • βœ”Add: rate limits, recovery codes, step-up, session protection.
  • βœ”One line: β€œTwo locks help only if the attacker cannot talk you into opening both.”
← Previous
Certificates and PKI
Next β†’
Zero Trust