Skip to content

Lesson 3 of 9 · 21m

OTP Operations: Enrollment, Lockout, Backup Codes, and Device Loss

The operational side of one-time codes: enrollment proof, attempt throttles, backup-code design, and what to do when phones disappear.

Most TOTP outages are not cryptographic failures. They are operations failures: incomplete enrollment, support agents resetting factors over chat, backup codes treated like decorative text, or lockout logic that turns a lost phone into a permanent denial of service. Build the operating procedure at the same time as the authenticator settings page.

Enrollment is a state machine

Do not flip totp_enabled when the secret is generated. Use explicit states:

none -> pending_enrollment -> active -> disabled
                 |
                 -> expired

The pending secret must expire quickly, commonly ten to fifteen minutes. The user proves possession by submitting a valid code, and only then do you activate the factor. Require recent authentication before enrollment or factor replacement; otherwise a hijacked session can add the attacker's authenticator and lock out the real user.

Backup codes are credentials, not decoration

Generate enough one-time codes for realistic recovery, commonly ten. Store only hashes, show them once, and make each code single-use. A good implementation records use count and last-used time because sudden backup-code use is often the first visible sign of phishing or device loss.

Backup code: 7K4M-2Q9D-X8RA
Stored:       argon2id(code + user id + purpose)
Properties:   single use, revocable, visible in security activity

Do not email the codes after the fact. If the user can retrieve them later from the same account, they are not independent recovery material.

Throttle guesses without creating lockout abuse

A naive lockout after five bad OTP attempts gives an attacker a way to deny access. Better controls combine rate limits per account, per IP, and per device fingerprint; step-up friction after repeated failures; and clear separation between authentication failure and factor-disable authority.

Support-driven reset is the highest-risk flow. Require strong evidence appropriate to the account value, preferably a delayed recovery process for sensitive accounts rather than instant actor-controlled reset.

Field notes

  • Show users which factor is enrolled and when it was added. Silent factor replacement is a classic account-takeover move.
  • Notify the user out of band when OTP settings change, but never include secrets or reset links in that notification.
  • Test the lost-phone path before launch. If the only recovery is 'contact support', you have built a social-engineering interface.
  • Keep SMS OTP available only when its risk is justified. It is better than password-only, not comparable to WebAuthn.

Was this lesson helpful?

Sign in to rate