LanguageEnglish
Build →

Learn · QuorumAuth

What is TOTP?

TOTP stands for time-based one-time password. It is a short code, usually six digits, that an authenticator app computes from a shared secret and the current time, and that changes every 30 seconds.

Updated

How both sides get the same code

  1. Shared secret, from QR → App computes six digits
  2. Clock: 30-second step → App computes six digits
  3. Shared secret, from QR → Server computes the same
  4. Clock: 30-second step → Server computes the same
  5. App computes six digits → Codes match: accepteduser types it
  6. Server computes the same → Codes match: accepted

The shared secret, delivered once through a QR code, and the current 30-second time step feed both the authenticator app and the server. Each computes an HMAC of the secret and the time step and truncates it to six digits. The user types the app's code, and the server accepts it when it matches its own.

Only the code travels: both sides compute it from the shared secret and the current 30-second step.

The six-digit code an authenticator app shows every 30 seconds is TOTP. It is standardized in RFC 6238, supported by common authenticator apps, and a clear improvement over a password alone. It is also easy to misjudge: it stops password reuse and credential stuffing, but it does not stop phishing.

What TOTP means

TOTP stands for time-based one-time password. Each part of the name says something:

  • One-time password (OTP): a code that is valid for a single use. OTP is the general category; TOTP is one way to produce one.
  • Time-based: the code is derived from the current time, so it expires on its own, after 30 seconds by default.

The standard behind it is RFC 6238, published by the IETF in 2011.

How TOTP works

TOTP is defined in RFC 6238. It builds on HOTP, the HMAC-based one-time password of RFC 4226, by replacing HOTP’s event counter with a time counter.

  1. Shared secret. At enrollment the server generates a random secret and shares it with the user’s authenticator app, usually through a QR code. Both sides store it.
  2. Time step. Both sides compute T = floor((now - T0) / X), where T0 is the Unix epoch and X is the step size, 30 seconds by default.
  3. HMAC. They compute HMAC(secret, T). The default hash is SHA-1; RFC 6238 also allows SHA-256 and SHA-512.
  4. Truncate. A fixed rule extracts a 31-bit number from the HMAC output and reduces it to 6 or 8 digits.
  5. Compare. The server computes the code for the current step, and usually the neighbouring steps to allow for clock drift, and compares it with what the user typed.

Because nothing travels except the code, the app works offline.

The enrollment URI

The QR code shown at enrollment encodes an otpauth:// URI, a de facto format popularised by authenticator apps rather than an RFC:

otpauth://totp/Example:ada@example.com?secret=JBSWY3DPEHPK3PXP&issuer=Example&digits=6&period=30

The secret is base32-encoded. Anyone who sees this URI can generate valid codes, so treat it as a credential.

TOTP vs HOTP vs OTP

OTP HOTP TOTP
What it is Any password valid for one use HMAC-based one-time password Time-based one-time password
Standard None as a category RFC 4226 RFC 6238
What changes the code Depends on the scheme A counter, advanced for each code The current 30-second time step
When a code stops working Depends on the scheme Once used, or once a later code is accepted At the end of its time step, or once used
Typical form Codes sent by SMS or email, or computed by an app Hardware tokens with a button Authenticator apps

HOTP and TOTP compute the code the same way; only the moving factor differs. An unused HOTP code stays valid until a later one is accepted, which gives a stolen code a long life. TOTP replaced the counter with the clock so every code expires within seconds. Codes sent by SMS or email are also OTPs, but the server generates and sends them instead of both sides computing them.

TOTP compared with other second factors

SMS code TOTP Passkey
Works offline No Yes Yes
SIM-swap risk Yes No No
Phishing Phishable Phishable (real-time relay) Resistant
Server stores Phone number Shared secret Public key only
User effort Wait for message, type code Open app, type code Unlock device
Standard Carrier-dependent RFC 6238 W3C WebAuthn

For the full comparison including passwords, see passkeys vs passwords.

Why TOTP is still phishable

  1. 1You → Fake sitePassword and code
  2. 2Fake site → Real siteRelays bothIn real time
  3. 3Real site → Fake siteAccepted: code still valid

You type your password and current code into a fake site. The fake site relays both to the real site in real time. The real site accepts, because the code is still valid.

TOTP stops reused and stuffed passwords, not phishing: a code typed into a fake site can be relayed to the real one in real time.

When to use TOTP

TOTP is a good choice when you need a second factor that works on any smartphone, without carrier dependence, and you cannot yet require passkeys. It is also a sensible recovery or fallback factor for users whose devices do not support passkeys. For high-risk roles, prefer passkeys or hardware security keys; the TOTP vs passkeys decision guide sets out who should be required to use what. When you are ready to move members off codes and onto passkeys, an organization’s sign-in policy decides which fallbacks remain.

Implementation pitfalls

  • Confirming enrollment without a code. Mark TOTP as active only after the user enters a valid code, which proves the app holds the right secret.
  • Accepting the same code twice. RFC 6238 says a verifier must not accept a code again after it has been used successfully. Track the last accepted time step.
  • Wide drift windows. Allowing many steps either side makes guessing easier. One step is usually enough.
  • No rate limiting. Six digits is a million combinations. Limit attempts.
  • Storing secrets in plaintext. A database leak would let attackers generate codes for every user. Encrypt seeds at rest.
  • No recovery path. Issue recovery codes at enrollment and let users regenerate them.
  • Changing the factor without proof. Replacing a user’s TOTP device should require the current factor, or the attacker who stole a password can simply enroll their own.

How QuorumAuth handles TOTP

QuorumAuth offers TOTP as a second factor. In its tested behaviour:

  • Enrollment returns an otpauth URI and a base32 secret, and the factor is not marked enrolled until verified.
  • Verifying with a correct code confirms enrollment and returns ten recovery codes; a wrong code is rejected. Regenerating recovery codes replaces all existing ones.
  • For a user with a confirmed factor, a correct password returns a challenge instead of a session. The session starts only after the correct code, the challenge reference is single-use, and a wrong code yields no session.
  • While a replacement authenticator is started but not confirmed, the current one keeps signing in.
  • Changing an existing second factor needs proof of it.
  • A second factor belongs to the person, not to one organization: it works in every organization they belong to, and an attacker holding only a password and the sign-in challenge cannot touch it. Enrolling again never replaces a confirmed authenticator.
  • A session opened with a recovery code cannot be refreshed into anything wider.
Is TOTP the same as 2FA?

TOTP is one way to provide a second factor. Other second factors include passkeys, security keys, and push approvals.

Why does my TOTP code change every 30 seconds?

RFC 6238 derives the code from the number of 30-second steps since the Unix epoch, so each step produces a new code.

Is TOTP phishing-resistant?

No. A phishing page can ask for the code and relay it to the real site while it is still valid. Passkeys resist this; TOTP does not.

What are recovery codes for?

They let a user sign in once each if they lose the device holding their TOTP secret. Store them offline.

Talk to sales about QuorumAuth.

QuorumAuth is sold through our sales team. The Build page shows the drop-in sign-in on your origin and how to reach sales about your stack.

Go to Build and contact sales →