security/two-factor-codes-how-your-phone-and-a-website-agree-on-6-digits.md

Two-factor codes: how your phone and a website agree on 6 digits

Security · 5 min read ·

Your phone shows a 6-digit code that changes every 30 seconds, yet it never talks to the website. How do both sides agree on the number?

They run the same recipe on the same two inputs: a secret shared once through the QR code, and the current time cut into 30-second windows. This is TOTP. Step through it below, then see why a slightly wrong phone clock still works but a badly wrong one doesn't.

A phone showing the six-digit code 287082 with a countdown bar and the words secret plus clock

$ ls security/

see all →