RMRM Full Stack & AI Engineer · All guides · Roadmaps
Security · guide

What is 2FA / MFA?

Two-Factor Authentication (2FA) and Multi-Factor Authentication (MFA) are security mechanisms that require users to verify their identity using two or more independent factors before gaining access to a system. They dramatically reduce the risk of unauthorized access even when passwords are compromised.

Core Concept: Authentication Factors

Authentication factors fall into three categories: something you know (password or PIN), something you have (a phone or hardware token), and something you are (a fingerprint or face scan). 2FA specifically combines exactly two of these factors, while MFA combines two or more. Using multiple independent factors means an attacker must compromise several separate mechanisms simultaneously, not just one.

How It Works Step by Step

After a user submits their primary credential (typically a password), the system triggers a second verification challenge before granting access. This challenge might deliver a one-time passcode (OTP) via SMS, prompt a push notification in an authenticator app, or require inserting a hardware key. Only after both factors are successfully verified does the system create an authenticated session.

Common MFA Methods Compared

TOTP (Time-based One-Time Passwords), used by apps like Google Authenticator and Authy, generate a cryptographic 6-digit code that refreshes every 30 seconds per the RFC 6238 standard. Hardware security keys (e.g., YubiKey) use the FIDO2/WebAuthn protocol and are the strongest option because they are phishing-resistant. SMS-based OTPs are the weakest second factor due to SIM-swapping and interception risks, but are still vastly better than a password alone.

Why MFA Matters for Security

Credential stuffing, phishing, and data breaches expose billions of passwords every year, making passwords alone insufficient for protecting accounts. MFA blocks the vast majority of automated account-takeover attacks because stolen credentials are useless without the second factor. Microsoft research has found that MFA can prevent over 99.9% of automated account compromise attacks.

Key Gotcha: Phishing-Resistant vs. Phishable MFA

Not all MFA is equally secure — SMS OTPs and TOTP codes can be phished in real time via adversary-in-the-middle (AiTM) proxy attacks that capture and replay the code before it expires. Only FIDO2/WebAuthn hardware keys and passkeys are truly phishing-resistant because the cryptographic response is bound to the exact origin domain of the legitimate site. For high-value accounts and enterprise environments, always prefer phishing-resistant MFA over SMS or app-based OTPs.

Best Practices for Implementation

Offer multiple second factors so users have a recovery path if one method is unavailable, and always provide secure account recovery options that do not bypass MFA entirely. Enforce MFA on all privileged and administrative accounts as a non-negotiable baseline. For developers integrating MFA, use a well-audited library or identity provider (e.g., Auth0, Okta, or AWS Cognito) rather than building TOTP or WebAuthn logic from scratch to avoid cryptographic implementation errors.

Go deeper with an AI tutor that teaches this in context — and quizzes you on it.
Open the app — free to start

© RM Full Stack & AI Engineer · All guides · Roadmaps · Open the app