LOGBOOK

HELP

Quiz Entry - updated: 2026.10.22

How does a time-based one-time password (TOTP), as in Google Authenticator, work?

App and server share a secret seed; both compute an HMAC of the seed and the current 30-second time step, truncate it to a short code, and the server accepts the login if the code the user types matches its own.

TOTP: the shared seed and the current 30-second time step feed HMAC and truncation on both the app and the server; the user types the 6-digit code and the server compares

* Both sides compute the same code independently: only the code travels, never the seed. *

  1. Enrollment: the server generates a random secret seed and shows it as a QR code; the app stores it. From now on both sides know the seed.
  2. Code generation: the app takes the current Unix time, divides it into steps (usually 30 seconds), and computes HMAC(seed, time step). A few bytes of the result are turned into a 6-digit code (dynamic truncation).
  3. Verification: the server does the same calculation, usually also allowing the neighbouring time step for clock drift, and compares.

In the authenticator schema: the seed is the secret value, the time step is the input value, HMAC plus truncation is the function, and the code is the output. Because the input changes every 30 seconds, an observed code is useless soon after. The method is standardised as TOTP (RFC 6238), built on the counter-based HOTP (RFC 4226).

Two limits remain: the seed is a shared secret stored on the server too, and a phishing site can relay a fresh code in real time, so TOTP is not phishing-resistant.

Go deeper:

From Quiz: IAM / Authentication Means: Factors, Authenticators and Credentials | Updated: Oct 22, 2026