Multi-Factor Authentication
A complete guide to Multi-Factor Authentication (MFA/2FA): SMS OTP vs authenticator apps vs FIDO2 security keys, and prompt bombing defense.
Passwords alone are no longer enough to protect sensitive accounts. Billions of username and password combinations from past data breaches are freely traded online, and attackers use automated tools to test these passwords across thousands of popular websites every day. If an account relies only on a password, anyone who guesses, steals, or phishes that password gains full access. It does not matter how complex the password was if the user was tricked into typing it on a fake login page. Multi-Factor Authentication (MFA) solves this by requiring two or more independent factors of evidence before granting access. Even if an attacker steals your password, they cannot log in without your physical phone or hardware security key. Enabling MFA stops the vast majority of automated account takeover attempts.
Definition
Multi-Factor Authentication (MFA) is a security method that requires users to provide two or more distinct types of evidence (such as a password plus a phone prompt or security key) before gaining access to an account or system.
Why It Matters
MFA is one of the most effective security improvements an individual or organization can make. It renders stolen passwords ineffective on their own. Major organizations, cloud providers, and regulatory standards now require MFA for all employee and administrative logins to prevent account takeover attacks.
How It Works
MFA methods vary in how they work and how secure they are against modern attacks: 1. SMS Text Message Verification (Basic): The server sends a 6-digit code via SMS. While much better than a password alone, SMS codes can be intercepted through SIM swapping (tricking a mobile carrier into moving a victim's phone number to an attacker's SIM card) or phishing sites. 2. Authenticator Apps and TOTP (Standard): Apps like Google Authenticator, Microsoft Authenticator, or Bitwarden generate a 6-digit Time-Based One-Time Password (TOTP) that rotates every 30 seconds. When setting up the app, your phone and the server share a secret key via a QR code. The app and server use the current time to calculate matching codes completely offline, without needing cellular service. 3. Push Notifications and Number Matching: The server sends a notification to your phone asking: 'Are you trying to sign in?' Attackers sometimes send dozens of repeated prompts late at night to annoy victims into tapping 'Approve' (a tactic called MFA fatigue or prompt bombing). To stop this, modern systems require number matching: the login screen displays a two-digit number that the user must type into their phone app. 4. FIDO2 and Hardware Security Keys (Strongest): Physical USB or NFC keys (such as YubiKeys) or built-in device authenticators (such as Touch ID or Windows Hello). These use public-key cryptography bound directly to the website's exact domain address. If you visit a fake phishing website, the key detects that the domain does not match and refuses to send credentials, providing mathematical protection against phishing.
How TOTP Works: 30-Second Code Calculation (RFC 6238)
Key Points
- MFA requires two or more DIFFERENT categories (Something you know, have, or are); two passwords do not count as multi-factor.
- SMS verification is susceptible to SIM swapping; authenticator apps and security keys provide stronger defense.
- TOTP codes work completely offline without internet or cellular connectivity by using synchronized time.
- FIDO2 and WebAuthn hardware keys provide complete protection against phishing websites by checking domain names cryptographically.
- Always keep backup recovery codes in a secure location when turning on MFA.
Steps
Install an Authenticator App
Use an authenticator application (such as Bitwarden, Google Authenticator, or 1Password) rather than relying on SMS text messages.
Scan the Setup QR Code
In your account security settings, scan the QR code to register the secret key in your authenticator app.
Save Emergency Recovery Codes
Store your one-time backup recovery codes in a safe place so you can regain access if your phone is lost or damaged.
Turn On Number Matching
If your organization uses push notifications, require number matching to prevent accidental approvals from MFA fatigue attacks.
Consider Hardware Security Keys
For critical accounts (like main email, administrative, and financial portals), use FIDO2 hardware keys like YubiKeys for phishing-resistant security.
Examples
The Bank Safe Deposit Box Analogy
Opening a safe deposit box at a bank requires two different keys: 1. Your personal customer key (Something You Have), and 2. The bank employee's master key (Second Possession Factor). Neither key works by itself; both must be present at the same time to open the box.
Real-World Examples
The Uber MFA Fatigue Incident (2022)
An attacker obtained login credentials for an Uber contractor and sent repeated push notification prompts late at night, accompanied by a message pretending to be IT support asking the user to accept the prompt to stop the notifications. When the contractor accepted, the attacker gained entry to internal company systems.
Cloudflare Phishing Defense (2022)
A widespread SMS phishing attack targeted employees across multiple technology companies, sending them to fake login pages that captured passwords and TOTP codes. While many organizations were compromised, Cloudflare employees remained protected because the company required FIDO2 hardware keys, which refused to authenticate on the fake domain.
Technical Examples
import crypto from "crypto";
// RFC 6238 Time-Based One-Time Password Implementation
export class TotpService {
/**
* Generates a 6-digit TOTP code for a given base32 secret and timestamp
*/
public static generateTOTP(secretBase32: string, timeStepSeconds = 30): string {
// Decode base32 secret into raw byte buffer
const key = this.base32Decode(secretBase32);
// Calculate time counter: T = floor(current_time_epoch / timeStepSeconds)
const epoch = Math.floor(Date.now() / 1000);
const counter = Math.floor(epoch / timeStepSeconds);
// Pack counter into 8-byte Big-Endian buffer
const counterBuffer = Buffer.alloc(8);
counterBuffer.writeBigInt64BE(BigInt(counter));
// Compute HMAC-SHA1(key, counter)
const hmac = crypto.createHmac("sha1", key);
hmac.update(counterBuffer);
const digest = hmac.digest();
// Dynamic Truncation: extract 4-byte integer from hash using last nibble as offset
const offset = digest[digest.length - 1] & 0x0f;
const binaryCode =
((digest[offset] & 0x7f) << 24) |
((digest[offset + 1] & 0xff) << 16) |
((digest[offset + 2] & 0xff) << 8) |
(digest[offset + 3] & 0xff);
// Modulo 1,000,000 to produce 6 decimal digits
const code = binaryCode % 1_000_000;
return code.toString().padStart(6, "0");
}
/**
* Verifies user token against secret with ±1 time step clock drift tolerance
*/
public static verifyTOTP(secretBase32: string, userToken: string): boolean {
const currentCode = this.generateTOTP(secretBase32);
// In production, also check T - 1 and T + 1 to account for clock skew
return crypto.timingSafeEqual(Buffer.from(currentCode), Buffer.from(userToken));
}
private static base32Decode(base32: string): Buffer {
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
let bits = "";
for (const char of base32.toUpperCase().replace(/=+$/, "")) {
const val = alphabet.indexOf(char);
if (val === -1) throw new Error("Invalid base32 character: " + char);
bits += val.toString(2).padStart(5, "0");
}
const bytes = [];
for (let i = 0; i + 8 <= bits.length; i += 8) {
bytes.push(parseInt(bits.substring(i, i + 8), 2));
}
return Buffer.from(bytes);
}
}Authenticator App (TOTP) vs Hardware Security Key (FIDO2)
| Aspect | Authenticator App (TOTP) | Hardware Security Key (FIDO2) |
|---|---|---|
| Phishing Resistance | Vulnerable if a user types code into a real-time proxy phishing site | Immune to phishing; the key binds authentication to the browser domain |
| SIM Swap Risk | Immune: Does not rely on phone carrier networks | Immune: Operates completely on hardware |
| Offline Usability | Works fully offline without an internet connection | Works fully offline without an internet connection |
| User Experience | Open app, view the rotating 6-digit code, and type it before expiry | Insert or tap the key on your device and touch the sensor |
| Cryptographic Type | Symmetric pre-shared secret (HMAC-SHA1) | Asymmetric public-key cryptography (ECDSA or Ed25519) |
| Cost | Free mobile software applications | Requires purchasing physical USB or NFC hardware keys |
Advantages
- Blocks Automated Attacks: Neutralizes mass credential-stuffing campaigns that rely on stolen password lists.
- Meets Security Standards: Required by major cybersecurity guidelines, insurance policies, and compliance audits.
- Simple to Enable: Most online services offer built-in support for authenticator apps and security keys.
Limitations
- Recovery Management: Users who lose their secondary device must follow recovery procedures to regain access.
- Hardware Costs: Purchasing physical keys for large distributed teams requires budgeting and shipping logistics.
Interview Questions
What makes FIDO2 / WebAuthn phishing-resistant compared to traditional TOTP codes?
FIDO2 hardware keys use public-key cryptography bound directly to the browser's origin URL. During authentication, the browser tells the key the exact domain currently in the address bar. The key signs the challenge using the private key registered for that specific domain. If a user is on a phishing site (like login.fake-domain.com), the key signs that fake domain instead of the real one. When the attacker passes the response to the real server, the real server rejects it because the domain signature does not match.
What is the difference between HOTP and TOTP?
HOTP (HMAC-based One-Time Password) uses an incrementing counter: each time you request a code, the counter increments on the token and on the server. If the button is pressed without logging in, the counters can become desynchronized. TOTP (Time-Based One-Time Password) replaces the counter with the current Unix time divided into 30-second steps, keeping both devices synchronized automatically without counter drift.
Practice Questions
- Turn on an authenticator app on one of your personal accounts, write down your backup recovery codes, and test logging in with the app.
- Check whether your laptop or phone supports built-in biometric authenticators (like Touch ID or Windows Hello) for passwordless logins.
