Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

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 app 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.

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 function. 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 token'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 phishing 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 stops a prompt Mia didn't expect, but a look-alike page can show her the real number.

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:

Checks in the delivered-code example
CheckWhy it matters
Account and purposeA code sent to recover an account or confirm an email change must not complete a sign-in.
Pending attemptThe code must complete the sign-in it was sent for, not another one.
Lifetime and unused stateAn expired or used code must fail, including when two requests try to use it at once.
Guess limitsA 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.

Mia types every digit of an emailed sign-in code correctly, but the sign-in attempt it was sent for has expired. What should the photo service do? 1 of 3

Choose one answer.

Mia gets an approval prompt from the photo service while she is not signing in anywhere. What should she do? 2 of 3

Choose one answer.

Mia's photo service uses number matching. She signs in on a look-alike page that passes everything to the real service, and chooses the number it shows her. What happens? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity