How does an authenticator-app TOTP code stay valid for only about 30 seconds?
code = HOTP(secret, floor(unix_time / 30))
- It combines a shared secret with the time window
- The server pushes a new code to the app each cycle
- A counter kept only on the server is incremented
- The phone fetches fresh codes from a cloud service
Both sides hash the same shared secret with the current time step, so the code rotates each window with no network traffic.
Play Cybersecurity ▸