Codes, links, and approval prompts
Many sign-ins ask for something short-lived instead of, or after, a password: a code in a message, a link in an email, a number from an app, or a tap on an approval prompt. Each one proves something different, and none of them can tell a real sign-in page from a convincing copy.
Another way to sign in
Mia Lane keeps her photos at the photo service. Some days she signs in with her password. On a borrowed laptop, she might prefer not to type it at all, and ask the service to email her a sign-in link instead. Later she may add an authenticator appSomething a person controls and uses to prove control of an account, such as a memorized password, an app that generates one-time codes, or a security key. It counts only after it has been registered to that account. to her phone, so that a stolen password alone is no longer enough to open her account.
These methods share an idea. The service creates or expects a secret that lasts only a short time, and Mia shows that she can receive it, read it, or produce it. What that proves depends on where the secret travels. A code sent to her mailbox proves that someone can read her mail. A code from an app on her phone proves that someone holds the secret the app was set up with. An approval prompt proves that someone could answer on a device she had already signed in with.
Throughout this lesson, keep the question from Methods, credentials, and factors in mind: what evidence did the service actually verify? A short-lived secret limits how long a copy is useful. It doesn't change who could have received it.
Delivered codes and links
The simplest short-lived secret is one the service delivers. For a text-message code, the service sends a few digits to the phone number Mia registered earlier, and she types them into the sign-in page. A correct code shows that someone could read messages sent to that number at that moment. It doesn't show that Mia alone controls the number, or that the phone is in her hand.
That difference matters because phone numbers change hands. A carrier can reassign a number that a customer gave up, and an attacker can sometimes persuade a carrier to move someone's number to a new SIM card, the small chip that ties a phone to a number. Messages can also appear on a locked screen where someone else can read them. NIST, the United States standards agency whose digital identity guidelines (SP 800-63B-4) many services follow, treats codes sent by text message or voice call as a restricted option for this reason. A service that offers them must tell people about the risk, offer at least one alternative that is not restricted, and plan for the day it stops using them.
An email code depends on access to Mia's mailbox. A mailbox can usually be opened from any device with the right password, so a correct code shows that someone can read Mia's mail, not that they hold a particular phone or computer. A magic link works the same way, except that the secret is part of a link, and the service checks it when Mia opens the link. Anyone who can read or forward her mail can use either one. For that reason the same NIST guidance doesn't accept email as an authenticationChecking evidence that someone, or some application, controls an account, such as a password or a passkey. It establishes which account is being used, not what that account may do. factor at all. An emailed code or link can sign someone in or help them recover an account, but it never makes a sign-in multi-factor.
A delivered secret should work only for its intended account, its purpose and a short time. Once it has been used, it must not work again, even if two requests arrive at the same moment. Some services also refuse a link opened in a different browser from the one that asked for it, so a link forwarded or intercepted along the way is less useful.
Links bring one more problem. Some email services open every link in a message to scan it for danger, before the person ever sees the email. If simply loading a magic link signed Mia in or used it up, the scanner would do one of those things on her behalf. A careful service makes the link open a page that asks Mia to confirm, and only that confirmation completes the sign-in.
Authenticator-app codes
An authenticator app produces codes without waiting for a message. When Mia sets one up, the photo service generates a secret and shows it to her, usually as a QR code, a square barcode that her phone's camera can read. The app scans it and stores the secret. From then on the service and the app hold the same value, the shared-secret pattern from Secrets and key pairs. Anyone who copies that QR code, or the setup key printed beside it, can produce Mia's codes too, which is why a service asks her to sign in recently before it shows one.
Most apps use time-based one-time passwords (TOTP), defined in the standard RFC 6238. The app combines the shared secret with the current time to calculate a short code. Time is counted in steps, usually 30 seconds long, and each step gives a new code, typically six digits. The calculation is an HMAC, the keyed tag from Secrets and key pairs, computed by default with SHA-1, an older hash functionTurning data into a short, fixed-size value called a hash, in a way that cannot be reversed and where changing one character changes the result completely. Services store password hashes instead of passwords, and signatures are made over a hash.. The service calculates the expected code from its own copy of the secret, so its stored secrets need the same protection as the app's. An older variant, HOTP (RFC 4226), uses a counter instead of the time: each press of a hardware tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret.'s button moves the counter on, and the service looks a few values ahead in case some presses were never used.
Because clocks can differ slightly, the service may accept a code from a neighboring time step, and RFC 6238 recommends allowing at most one step back. It also limits how many wrong codes it accepts, because six digits allow only a million possibilities. And it remembers the last time step it accepted for Mia, so a code that has worked once is refused if it is entered again within its 30 seconds. Someone who watched her type it gains nothing.
None of that helps if Mia types the current code into a fake page. As Proving control of an account showed, whoever runs a look-alike page can pass her password and code straight on to the real service while the code still works. A changing code is still something a phishingTricking someone, usually with a message and a look-alike sign-in page, into handing over the evidence that opens their account, such as a password or a one-time code. page can ask for.
Approval prompts
Instead of asking Mia to type a code, a service can send an approval request to an app she has set up, or to another device or browser where she is already signed in. She sees where the sign-in comes from and chooses to approve or deny it. The answer must come from that app or device and belong to the sign-in attempt being completed.
What an approval proves depends on where it lands. A dedicated app holds a key of its own that was set up for Mia's account, so its answer is possession evidence. A prompt sent to another signed-in browser is only as strong as the sign-in that browser made. If that browser signed in with Mia's password alone, approving from it adds nothing that a stolen password doesn't already give.
Prompts have a weakness of their own. If someone else starts a sign-in with Mia's password, she might receive a prompt she wasn't expecting. Repeated prompts can wear a person down until they approve one just to make them stop, and a quick tap is easy to give without thinking.
Number matching is designed to stop that. The sign-in page shows a number, and the prompt asks Mia to choose the same number before it approves. If Mia didn't start the sign-in, there is no number on her screen to compare, so a tired tap on an unexpected prompt is more likely to deny the sign-in than complete it. Mia should deny a prompt she didn't expect and then check her account through a route she trusts, such as typing the service's address herself. If a request is denied, expires or never reaches her, the sign-in attempt has not succeeded.
She started it
- Who started it
- Mia
- Number on her screen
- The real number
- Her choice
- The same number
Mia is signed in
Someone has her password
- Who started it
- Someone else
- Number on her screen
- None
- Her choice
- A tired tap
More likely to deny
A fake page relays it
- Who started it
- The fake page
- Number on her screen
- The real number
- Her choice
- The same number
Completes the attacker's sign-in
Number matching doesn't stop a relay.
Number matching doesn't stop a relay, though. If Mia signs in on a fake page that passes everything to the real service, the real service shows its number to the fake page, the fake page shows it to Mia, and her correct choice completes the attacker's sign-in.
Following a code
Here is a simulated request that submits a delivered code, and the service's answer. The address and values are fictional; nothing here sends a real request. The request names the sign-in attempt the code belongs to and the six digits Mia typed.
POST https://auth.photos.example/sign-in/verify-code
Content-Type: application/json
{"attempt_id":"example-attempt","code":"000000"}
HTTP/1.1 400 Bad Request
Content-Type: application/json
{"error":"Code could not be accepted. Start a new attempt."}Suppose those digits match a code the service sent Mia earlier, but the sign-in attempt it belonged to has expired. The service refuses it. Matching digits are only one of the checks a delivered code has to pass:
| Check | Why it matters |
|---|---|
| Account and purpose | A code sent to recover an account or confirm an email change must not complete a sign-in. |
| Pending attempt | The code must complete the sign-in it was sent for, not another one. |
| Lifetime and unused state | An expired or used code must fail, including when two requests try to use it at once. |
| Guess limits | A six-digit code has only a million values, so repeated wrong answers must be limited. |
The answer itself is deliberately vague. It doesn't say whether the digits were wrong, expired or already used, because each of those details would help someone who is guessing. Mia only needs to know that she should start again and ask for a new code.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Sign in by email link, email code, authenticator code and approval promptSign Mia in with an email link and an email code, set up an authenticator app and see a reused code refused, then deny and approve a number-matched sign-in from another browser.