How it works
The three kinds of factors
A “factor” is a type of proof. Real 2FA combines two different types. A password plus a security question is still one type (two things you know).
| Factor | Meaning | Examples |
|---|---|---|
| Knowledge | Something you know | Password, PIN |
| Possession | Something you have | Phone (SMS, authenticator app, push), security key |
| Inherence | Something you are | Face ID, fingerprint (see biometric authenticationBiometric authenticationUnlocking a saved login with Face ID, Touch ID or a fingerprint.Open in glossary →) |
The flow, step by step
- First factor. The user enters email and password. The server checks them but does not start a full session yet. It remembers “password OK, waiting for step 2”.
- The server issues a challenge. For SMS or email it generates a random code (usually 6 digits), stores it with an expiry (often 5 to 10 minutes) and sends it. For an authenticator app nothing is sent: the app already knows how to compute the code.
- The user enters the code. They type it, paste it, or accept the phone’s autofillAutofillWhen the browser, phone or a password manager fills form fields with saved data in one tap.Open in glossary → suggestion. Many apps submit automatically once all digits are in.
- The server checks it. Right code, not expired, not used before, and not too many wrong attempts? Then the code is marked as used and a sessionSessionThe period during which a user stays logged in without entering their credentials again.Open in glossary → starts.
- Optional: remember this device. The server gives the device a long-lived token, so this phone or browser skips step 2 for, say, 30 days.
Where the code comes from
| Method | How it works | Watch out for |
|---|---|---|
| SMS | Server texts a random code to the phone number | Slow or missing SMS, roaming, SIM swap attacks, cost per SMS |
| Server emails a code or a link | Spam folder, delays, weaker if the email account uses the same password | |
| Authenticator app (TOTP) | App and server share a secret at setup; both compute a new code every 30 seconds from the secret and the current time | Phone clock out of sync, lost phone, setup via QR code |
| Push approval | The app on a trusted phone shows “Is this you logging in?” with Approve/Deny | Users approving pushes they didn’t start (“push fatigue”), no internet on the phone |
| Backup / recovery codes | A list of single-use codes shown once at setup, to use when the phone is lost | Each code works once, the list can be regenerated (old list must stop working) |
SMS is the most familiar method, but not the strongest. The US NIST digital identity guidelines (SP 800-63B) classify codes sent by SMS or phone call as a restricted method, because of risks like SIM swaps (an attacker talks the mobile carrier into moving your number to their SIM card) and interception, and expect services to offer users an alternative. That’s why many products also support authenticator apps or security keys.
Authenticator apps and clock skew
TOTPTOTPTime-based one-time password: an authenticator app and the server compute the same code every 30 seconds.Open in glossary → (time-based one-time password) is what Google Authenticator, Microsoft Authenticator and similar apps use. Nothing is sent over the network: the server and the app both compute the code from the shared secret (a hidden key they exchanged when you scanned the setup QR code) and the current time, in steps of (by default) 30 seconds. That means the phone’s clock matters. Try it:
Dev note
otpauth:// link with the secret, the issuer and the account name.Authenticator app
Northbank · leo@test.com
––– –––
Server accepts
Same secret + server time. One step either side is a common tolerance.
previous
––––––
current
––––––
next
––––––
Many servers also accept the code from one step before and after the current one, to cover small clock differences and the seconds it takes to type. If the phone clock is set manually and drifts further, every code is “wrong”. That’s clock skewClock skewThe difference between a device's clock and the server's, which breaks time-based features.Open in glossary →, and it’s worth a test: set the device time manually a minute or two off and see what the app tells the user.
OTP input: the small details that matter
The code field looks simple, but it’s where most user frustration happens. Everything from Text Field applies, plus:
- One-time code autofill. iOS suggests a code from Messages (or Mail) above the keyboard when the field is marked as a one-time-code field. Android can do the same, either automatically or after a short consent prompt, and Chrome on Android can fill SMS codes on websites too. Test that the suggestion appears and fills the field correctly.
- Paste. People copy codes from SMS, email or a password managerPassword managerA tool that stores credentials and fills them into login forms, like Apple Passwords, Google Password Manager or 1Password.Open in glossary →. Pasting
318452,318 452or318452(with spaces) should all work. - Numeric keyboard. The field should open the number pad, but keep the value as text: codes like
042917start with a zero, and a number would lose it. - Auto-submit. Submitting when the last digit is entered is convenient, but it must fire exactly once, and the user must still be able to fix a typo.
- One field or six boxes? Both are common. A single field is simpler and usually works better with autofill, paste and screen readers. Separate boxes look nice but often break paste, backspace, and focus movement. If you test boxes, try paste, backspace across boxes, and tapping a box in the middle.
Dev note
Example requirements
Check this part
Which pair is real two-factor authentication?
An authenticator code is always rejected on one phone, but works on others. What should you check first?
Why should the code field open a numeric keyboard but keep the value as text?