Two-factor authentication

Add a second check to account access.

Enroll a TOTP authenticator, verify time-based codes during sign-in, and use bounded attempts and replay checks around verification.

Prepare recovery before enrollment

TOTP adds a second check to an account; it does not replace secure password storage, session invalidation, rate limits, or a verified recovery process. Complete signup, verification, sign-in, password recovery, and administrative recovery from the authentication guide first.

Enroll and confirm in one controlled session

  1. Sign in as the ordinary user who will own the second factor.
  2. Start the TOTP enrollment action exposed by the active release.
  3. Show the returned secret or QR representation once, over TLS, and do not write it to application logs.
  4. Add it to the authenticator and submit a current code to confirm enrollment.
  5. Require confirmation before treating the factor as active.

Resolve exact action names and payload fields from the running server’s OpenAPI/metadata because they are part of the release contract. Do not invent client-side enrollment state.

Verify success and refusal paths

  • A current unused code completes the intended sign-in or confirmation flow.
  • An incorrect code is rejected without revealing whether another factor was correct.
  • An expired or replayed code is rejected according to the deployed release’s window.
  • Repeated failures are rate-limited and observable without recording the code.
  • Password reset or factor recovery has the documented effect on existing sessions.

Make recovery narrower than normal sign-in

Recovery should require a separately verified channel or an administrator procedure with audit evidence. Never let knowledge of the password alone silently remove the second factor. Notify the account owner when a factor is added, removed, or recovered, and retest access from an older session after the change.

Do not publish example TOTP secrets from a real account.Use disposable accounts and secrets in screenshots, examples, logs, and tests.

Account flow

Enroll

Associate a generated TOTP secret with the authenticated account.

Confirm

Require a valid authenticator code before treating enrollment as complete.

Verify

Check the time window, attempt allowance, and prior accepted value during authentication.

Recover

Design an administrator or product recovery path before requiring a second factor.

Start with the complete account model.