Multi-factor authentication
Understand the idea
A second factor is a fresh code, or a check you only demand when the request looks wrong.
The idea
adds a factor the password is not. TOTP, the time-based one-time password, is a shared secret and a counter. The counter is the Unix time divided by 30. The server and the authenticator app both run HMAC-SHA1, take a dynamic offset into the digest, and keep six digits. A code typed ten seconds later is still the same step. A code from ninety seconds later is the next steps, and it must not match. Adaptive, or risk-based, MFA does not ask for that code on every quiet login from the usual IP. It asks when the IP is new, the device is new, or the action is sensitive. The last two lines are that policy as a condition, not a vendor score.
What changes
| Situation | What you already know | What you ask next |
|---|---|---|
| Same IP, ordinary action | Password or session | Nothing extra |
| New IP or a sensitive action | Password or session | A current TOTP code |
| Code from an old time step | The secret | Reject it. The step moved. |
The command
Same step matches, a later step does not
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
The mistake
Check the result
same step is true. later step is false. step up is true for the new IP, and quiet is false for the usual IP.
Guided challenge
Use the current time step
totp currently hashes counter 1 for every time, so a later clock still matches. Divide the time by 30 and use that counter.
Use the current time step
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
EXPECTED RESULT
same step true later step false step up true quiet false
Hints 0/2
Use all hints or make 3 failed checks (0/3).
Free exploration
Change this example and run it again. Each run is a new process. Nothing is saved.
Your variation
3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.
Quiz
A quick check for understanding. Retry as often as you like; your learning path stays open.
Ready to call this one understood?
Mark this lesson complete to earn 150 XP. You can always revisit it.