2 / 6 · Intermediate
Two-step sign-in
A six-digit code has exactly 1,000,000 possible values, so a thief with your password who gets five guesses has a 1 in 200,000 chance.
Jump to the 10 practice questionsYou will learn
- Tell the three kinds of factor apart
- Rank SMS codes, app codes and security keys
- Keep recovery codes and a second factor ready
Before this: Passwords and passkeys
1Explain
A thief has your password. What are the odds of the code?
Start with a puzzle. Someone has stolen your password, but the site also asks for a six-digit code, and the thief gets five tries. How likely is a lucky guess? Work it out in the exercise below before reading on.
2Practice
Count the codes
Fix the exponent so the program prints how many six-digit codes exist, then the chance of guessing one in five tries.
1000000
0.000005const codes = 10 ** 1; // change: how many six-digit codes are there (000000 to 999999)?
console.log(codes);
console.log(5 / codes); // chance of guessing right in 5 tries
Hint
Six digits, ten choices each.
A solution
const codes = 10 ** 6;
console.log(codes);
console.log(5 / codes);
3Explore
One in 200,000
Six digits run from 000000 to 999999, which is 10⁶ = 1,000,000 codes. Five guesses give a chance of 5 in 1,000,000, or 1 in 200,000. With the password alone the thief was already in. With the code, almost never. That gap is what multi-factor authentication buys you.
The second line is the "1 in" number: one lucky guess in that many attempts.
const digits = 6;
const tries = 5;
const codes = 10 ** digits;
console.log(codes);
console.log(codes / tries);1000000
2000004Problem
Six-digit codes
How many different six-digit codes are there?
Hint
000000 to 999999.
Solution
Answer: 1000000
All six positions allow ten digits, including a leading zero: 10⁶ = 1,000,000, from 000000 to 999999. Do not leave out codes that start with zero.
5Explain
Three kinds of proof, and why two passwords are still one
Multi-factor authentication, often called two-factor or two-step sign-in, asks for proof from more than one kind of factor. CISA sorts the kinds into something you know (a password or PIN), something you have (a phone or a security key) and something you are (a fingerprint or face). Two passwords are still one kind. CISA's advice for everyone is to turn MFA on for every account that offers it, starting with email, social media and financial accounts.
The three kinds of factor. Two-step sign-in combines two different kinds; two passwords are still one kind.
6Problem
Real two-factor
Which pair is real two-factor authentication?
Hint
Two different kinds of proof.
Solution
Answer: A password and a code from an app on your phone
Know plus have. A security question is another thing you know.
7Problem
MFA first
Which account should get MFA first?
Hint
It can reset all the others.
Solution
Answer: Email
Reset links for other accounts go to your email.
8Explain
Codes that can be relayed, and keys that cannot
The common options differ in how well they hold up. A code sent by text message or voice call travels over the phone network. NIST classes this as a restricted authenticator. It is still allowed, but services must offer an alternative and warn users of the risks. They should watch for signs such as a recent SIM change or number transfer. Criminals can talk a phone company into moving your number to their SIM. A code from an authenticator app is generated on your phone and never crosses the network.
9Problem
SMS codes
How does NIST class codes sent by SMS or voice call?
Hint
Allowed, with a warning and an alternative.
Solution
Answer: Restricted
Allowed, but services must offer an alternative and explain the risks.
10Explain
Codes can be relayed
All of these can still be phished. A fake login page asks for your code, you type it in, and the criminal passes it to the real site within seconds. NIST says plainly that methods involving manual entry of a code are not phishing-resistant, because nothing ties the code to the real site. CISA calls phishing-resistant MFA the gold standard and says the only widely available kind is FIDO/WebAuthn: security keys and passkeys, which, as the previous unit showed, only answer to the site they were made for.
11Problem
Typed codes
Why are typed one-time codes not phishing-resistant?
Hint
Nothing ties the code to the real site.
Solution
Answer: A fake site can pass the code to the real one
Nothing binds the code to the real site (NIST 3.2.5).
12Problem
The gold standard
According to CISA, the only widely available phishing-resistant MFA is
Hint
Security keys and passkeys.
Solution
Answer: FIDO/WebAuthn
Security keys and passkeys use FIDO/WebAuthn.
13Problem
Twenty prompts
Your phone shows twenty approval prompts you did not request. What should you do?
Hint
Someone already has your password.
Solution
Answer: Deny them and change that account's password
Someone has your password and is trying push bombing.
14Problem
Against push bombing
What does CISA recommend against push bombing?
Hint
The phone asks for the number shown on the screen.
Solution
Answer: Number matching
Typing the number shown on screen stops blind approvals.
15Explain
Before the phone goes missing
When you turn on two-step sign-in, most services show a list of one-time recovery codes. NIST calls these look-up secrets. They are your way back in if you lose your phone, so keep them somewhere safe and separate from the phone: printed and stored at home, or in a password manager. Never paste them into an email to yourself, and never read one out to someone who calls you. No genuine support team needs it.
16Problem
Recovery codes
Where should recovery codes be kept?
Hint
Not on the phone and not in your email.
Solution
Answer: Somewhere safe, separate from your phone
Keep recovery codes safe and separate from the phone, because they replace the missing factor if it is lost. A copy available only on that phone would be lost with it.
17Explain
Plan for a lost phone
Plan for a lost or replaced phone before it happens. Most services let you register more than one second factor, for example an authenticator app and a security key, or a passkey on two devices. When you change phones, move your authenticator app or passkeys to the new phone before you wipe the old one. If a phone is lost, sign in with a recovery code or another factor and remove the lost device from each account.
18Practice
An easy code field
Make this code field easy to fill: tie the label to it with for, and add autocomplete="one-time-code" and inputmode="numeric" so phones offer the code and a number pad.
- label tied to the field
- autocomplete one-time-code
- inputmode numeric
<form>
<label>Six-digit code</label>
<input id="otp" type="text">
<button>Verify</button>
</form>Hint
for="otp" on the label, two attributes on the input.
A solution
<form>
<label for="otp">Six-digit code</label>
<input id="otp" type="text" autocomplete="one-time-code" inputmode="numeric">
<button>Verify</button>
</form>19Problem
The autocomplete value
Hint
The value used in the lab.
Solution
Answer: one-time-code
autocomplete="one-time-code" (MDN).
20Explain
Common mistakes
"A password plus a security question is two-factor."
Both are things you know, so it is still one kind of factor. Two-factor needs a different kind, such as a code from an app on your phone or a security key.
"Codes by text message stop phishing."
A fake page can ask for the code and pass it on within seconds. NIST says codes entered by hand are not phishing-resistant, and it classes SMS codes as restricted because a phone number can be moved to a criminal's SIM.
"If approval prompts keep coming, approving one makes them stop."
It does stop them. The attacker is in. A flood of prompts you did not ask for means someone has your password: deny them and change that password.
"Recovery codes are safe in an email to myself."
Whoever gets into that inbox then has the codes as well. Keep them apart from the phone and the email, on paper at home or in a password manager.
21
Summary
- MFA combines different kinds of factor: know, have, are.
- Turn it on everywhere, starting with email.
- Typed codes can be relayed by a fake site; FIDO/WebAuthn cannot.
- Keep recovery codes safe and never share them.