TOTP
What is TOTP?
TOTP, or Time-Based One-Time Password, is a security method that generates a short-lived code for multi-factor authentication. It adds a possession factor to a password because the user must also access an enrolled authenticator app or device. TOTP is an open standard, not a specific product, so Google Authenticator and Microsoft Authenticator can generate TOTP codes without being TOTP itself.
How TOTP authentication works
TOTP relies on a shared secret and the current time. The standard is defined in RFC 6238.
- During enrollment, the application creates a high-entropy secret and displays it as a QR code or manual setup key.
- The authenticator app stores the secret after scanning or entering it.
- The app combines that secret with the current time interval, commonly 30 seconds, to generate a temporary code.
- The user enters the code at sign-in, and the server calculates the expected code from its stored secret and clock.
- The server accepts a close matching time window when needed for minor clock drift, then completes verification.
TOTP vs. SMS codes and passkeys
An authenticator app is a tool for generating TOTP codes. It is not the same thing as the TOTP protocol.
| Method | Credential location | Network need | Phishing resistance |
|---|---|---|---|
| TOTP | Authenticator app | No, after setup | Limited, codes can be relayed |
| SMS code | Mobile carrier and phone | Yes | Limited, vulnerable to interception and relay |
| Passkey | Device security hardware or password manager | Usually needed for sign-in | Strong, tied to the genuine site |
Benefits of TOTP for application security
TOTP remains a practical second factor for many applications.
- Codes can be generated offline after enrollment.
- It works across many services and authenticator apps.
- It avoids relying on per-message SMS delivery.
- It makes a stolen password alone less useful to an attacker.
Practical limits of TOTP
TOTP improves password-based sign-in, but it is not phishing-resistant authentication.
- A convincing fake sign-in page can capture and relay a current code in real time.
- Anyone who obtains the setup QR code or secret can generate valid codes.
- Lost devices and poor recovery processes can lock out legitimate users.
- Clock mismatch and accepted time windows can cause failed or replayed attempts if validation is weak.
TOTP implementation and recovery best practices
Secure implementation matters as much as the code generator.
- Use a well-reviewed, standards-compliant TOTP library.
- Generate strong secrets, encrypt them at rest, and never log them.
- Show enrollment QR codes only within an authenticated setup flow.
- Rate-limit verification and reject a code after successful use within its accepted window.
- Provide single-use recovery codes and offer passkeys or other stronger factors where feasible.
Using TOTP in apps built with Emergent
When building a secure sign-in flow with an AI app builder or AI web app builder, specify TOTP enrollment, verification, recovery codes, rate limits, and encrypted secret handling from the start. Emergent can help turn those requirements into full-stack web and mobile application flows while keeping authentication behavior explicit and testable.
on Emergent today

