What Is Two-Factor Authentication? A Plain-English Guide
Two-factor authentication asks for a second proof beyond a password. How codes, apps, passkeys and SMS compare, and what to ask an AI builder to add it.
Mythex Team · · 7 min read
Two-factor authentication (2FA) is a login that asks for two different kinds of proof that you are who you say you are — typically something you know, like a password, plus something you have, like your phone or a security key. If a criminal steals or guesses your password, they still can't get in without the second factor. It is one of the simplest ways to protect accounts that matter.
Why it matters when you build with AI
When you ask an AI builder for "login", you usually get email and password. That's a fine start, but passwords get reused, phished and leaked. If your app holds anything valuable — customer records, invoices, admin controls, payment settings — a single stolen password could expose all of it.
2FA also affects decisions you might not think about at first:
- Who must use it. Optional for everyone, required for admins, or required for all?
- Which methods you support. Codes from an app, text messages, passkeys, security keys.
- What happens when someone is locked out. Lost phones are the most common support request for any app with 2FA.
- Where it's enforced. The check has to happen on the server. A 2FA screen that only hides the page in the browser can be skipped.
You don't have to build the cryptography yourself — well-tested libraries and auth providers handle that. But you do need to know what to ask for.
An everyday analogy
Think of a bank safe-deposit box. To open it, you need your ID (something the bank checks you are or know) and the physical key (something you have). A thief who copies your signature still doesn't have the key. A thief who pickpockets the key still can't pass the ID check.
2FA works the same way. The password is the signature; the phone or security key is the physical key. Each one alone is not enough.
The three kinds of factors
Security standards, such as the US National Institute of Standards and Technology's digital identity guidelines, group factors into three kinds:
| Factor | Examples |
|---|---|
| Something you know | Password, PIN |
| Something you have | Phone with an authenticator app, a security key, a device holding a passkey |
| Something you are | Fingerprint, face — usually used to unlock a device that then does the real check |
The key word is different. A password plus a security question is two things you know, so it isn't true two-factor authentication. If one leak can reveal both, it only counts as one.
The common 2FA methods compared
| Method | How it works | Strength | Notes |
|---|---|---|---|
| SMS code | A code is texted to your phone number | Weakest | Vulnerable to SIM swapping and phishing, but far better than no 2FA |
| Email code | A code is emailed to you | Weak | Only as safe as the email account |
| Authenticator app (TOTP) | An app like Google Authenticator generates a new 6-digit code, usually every 30 seconds | Good | Works offline; still phishable if a fake site asks for the code |
| Push approval | An app asks "Is this you?" and you tap approve | Good | Watch for "approve fatigue", where users tap yes to stop repeated prompts |
| Passkey or security key | A cryptographic key on a device proves you're on the real site | Strongest | Resistant to phishing because it won't respond to a lookalike domain |
NIST's guidance treats methods where you type a code (SMS, email, authenticator apps) as not phishing-resistant, and marks sending codes over the phone network as "restricted". Passkeys and hardware security keys, based on the WebAuthn/FIDO2 standards, are the ones it counts as phishing-resistant.
A practical takeaway: an authenticator app is a strong, easy default for most apps, and passkeys are worth offering if your users are comfortable with them.
A worked example: 2FA for a client portal
Say you've built a portal where a small accounting firm shares tax documents with clients. Here's how a sensible 2FA setup works, step by step.
Turning it on (enrolment). Priya, a client, opens Settings and clicks "Turn on two-factor authentication." The app generates a secret and shows it as a QR code. She scans it with her authenticator app, which starts showing six-digit codes. She types the current code back into the portal to prove the setup worked. The app shows ten recovery codes and asks her to save them somewhere safe.
Logging in afterwards.
- Priya enters her email and password. The server checks them.
- Instead of logging her straight in, the server marks the session as "password OK, second factor pending" and shows the code screen.
- She types the code from her app. The server checks it against her stored secret, allowing for a little clock drift.
- Only now does the server create a full session and let her see documents.
What an attacker sees. If Priya's password leaked from another site, the attacker gets stuck at step 3. Every failed code attempt is counted, and after several wrong tries the account is temporarily locked and Priya gets an email.
Losing her phone. Priya uses one of her recovery codes to log in, turns 2FA off and on again with her new phone, and gets fresh recovery codes. The used code can never be used again.
For staff. The firm's accountants can see every client's files, so the portal requires 2FA for staff accounts; they can't reach the dashboard until they've enrolled.
Common terms explained
| Term | What it means |
|---|---|
| 2FA / MFA | Two-factor / multi-factor authentication: logging in with more than one kind of proof. |
| Factor | One kind of proof: something you know, have or are. |
| TOTP | Time-based one-time password — the rotating codes in authenticator apps. |
| Shared secret | The hidden value, set up via QR code, that both the app and your phone use to generate matching codes. |
| Recovery (backup) codes | Single-use codes for getting in when you've lost your second factor. |
| Passkey | A login credential stored on your device that uses public-key cryptography instead of a password. |
| Security key | A small physical device (USB or NFC) that does the same job as a passkey. |
| SIM swapping | Tricking a mobile carrier into moving someone's number to a new SIM, so texts go to the attacker. |
| Phishing | A fake site or message that tricks people into handing over passwords or codes. |
| Step-up authentication | Asking for the second factor again before a sensitive action, like changing payout details. |
Common mistakes and misconceptions
- "2FA makes an account unhackable." It makes it much harder. Phishing sites can still capture typed codes in real time, which is why passkeys exist.
- Checking the code only in the browser. If the server issues a full session after the password, the code screen is decoration. The server must refuse access until the second factor passes.
- No limit on code guesses. A six-digit code has a million possibilities. Without rate limiting and lockouts, an attacker can simply keep guessing.
- Forgetting recovery. No recovery codes means every lost phone becomes a support ticket, or a locked-out customer.
- Storing the TOTP secret carelessly. The shared secret should be encrypted in the database, and never shown again after setup.
- Letting users turn 2FA off without re-checking. Disabling 2FA or changing the email should require the password and a current code.
- A password plus a security question counts as 2FA. It doesn't — both are things you know.
What to ask your AI builder for
- "Add optional two-factor authentication using an authenticator app (TOTP), with a QR code for setup and a confirmation code before it's switched on."
- "Show ten single-use recovery codes when 2FA is enabled. Store them hashed, like passwords."
- "Enforce 2FA on the server: no full session until the second factor passes."
- "Limit code attempts and lock the login for 15 minutes after repeated failures. Email the user when that happens."
- "Require 2FA for admin accounts."
- "Ask for the password and a current code before disabling 2FA or changing the account email."
- "Use a well-known library or our auth provider's built-in 2FA — don't write the crypto yourself."
- "Explain which method you used and where the secrets are stored."
If you use a hosted auth provider, check whether it already offers 2FA or passkeys; turning on a built-in feature is usually safer than custom code. The step-by-step version is in how to add two-factor authentication, and what authentication is covers the login basics underneath it.
Two-factor authentication in Mythex
Mythex doesn't include a built-in login system for your app's users, so 2FA is part of whatever auth approach you choose — your own email-and-password login backed by the project's database, or a hosted provider that offers 2FA. You ask the agent to add it in chat, and any provider keys go in project secrets rather than in the chat itself. The docs recipe on adding login to your app has a starter prompt to adapt, and security for apps you build covers the habits around keys. Before launch, run through the security checklist for AI-built apps.
Questions
What is two-factor authentication in simple terms?
Two-factor authentication (2FA) means logging in takes two different kinds of proof, usually your password plus a code from your phone or a security key. Someone who steals only your password still can't get in.
Is 2FA the same as MFA?
Nearly. Multi-factor authentication (MFA) means two or more factors; two-factor authentication is the most common case with exactly two. In everyday use the terms are used interchangeably.
Is SMS two-factor authentication safe?
It is much better than a password alone, but it is the weakest common option. Text messages can be intercepted or redirected through SIM swapping, and a fake login page can trick people into typing the code. Authenticator apps are stronger, and passkeys or security keys are stronger still.
Does my app need two-factor authentication?
If accounts hold money, private data, or admin power over other users, offering 2FA is a good idea, and requiring it for admins is common. For a simple hobby app it can be optional or left for later.
What happens if a user loses their phone?
That is what recovery codes are for: a short list of one-time backup codes shown when 2FA is turned on. Without them, recovery usually means a manual identity check by the app's owner, so plan it before launch.