One-time password (OTP)
Also known as: OTP, one-time code, SMS code
A short code that works for a single login and then expires, sent by text message or shown in an app.
Draft - this entry has not been reviewed yet.
Formal
A code valid for one use or a short time window, worked out by an app or token from a shared secret and the clock or a counter, or sent by SMS - used as the "something you have" factor in MFA.
In plain English
Like a ticket that is torn in half at the door - it gets you in once, and a copy is worth nothing afterwards.
In practice
A lawyer at a Danish law firm logs in to the case system from home; after her password she types the six numbers shown in an app on her phone, which change every 30 seconds.
Why it matters
A stolen password alone no longer gets anyone in, but a code can still be tricked out of a person on a fake page, so phishing-proof methods are stronger.
How to put it into practice
The usual steps, in order. Adapt them to your organisation.
- Choose the variant, normally TOTP (RFC 6238) in an authenticator app, HOTP (RFC 4226) for hardware tokens, and SMS codes only as a documented exception.
- Generate a random secret per user on the server, at least 128 bits and preferably 160 as RFC 4226 recommends, and show it once at enrolment as a QR code with the text key beside it.
- Switch OTP on for the account only after the user has typed one valid code, which proves the app and the server agree.
- Store the secrets encrypted with a key kept outside the database, for example in an HSM or key vault, because the server must be able to read them to check codes.
- Accept a code only within a narrow window, normally the current 30-second step plus at most one step on either side for clock drift and delay.
- Reject any code that has already been accepted, and limit failed attempts per account with a lockout or growing delays.
- Issue single-use recovery codes at enrolment, and require re-authentication and notify the user whenever OTP is reset or a new device is added.
- Plan the move to passkeys or security keys for administrators and other high-risk users, since phishing kits can relay a one-time code in real time.
Common pitfalls
- Having no limit on failed attempts, so an attacker can work through the million possible six-digit codes.
- Letting the same code be used twice within its window.
- Storing OTP secrets unencrypted in the same database as the password hashes.
- Treating SMS codes as equal to app codes despite SIM swapping and interception.
Good guides
- RFC 6238 - TOTP, Time-Based One-Time Password Algorithm(opens in a new tab) · IETF
- RFC 4226 - HOTP, An HMAC-Based One-Time Password Algorithm(opens in a new tab) · IETF
- NIST SP 800-63B-4 - Digital Identity Guidelines, Authentication and Authenticator Management(opens in a new tab) · NIST
- OWASP Cheat Sheet Series - Multifactor Authentication(opens in a new tab) · OWASP
Technical deep dive
Two open algorithms dominate. HOTP (RFC 4226, 2005) computes HMAC-SHA-1 over an 8-byte counter using a shared secret K, then applies dynamic truncation: the low four bits of the last byte of the 20-byte HMAC select an offset, four bytes from that offset are read as a 31-bit integer, and the result modulo 10^d gives a d-digit code (six by default). TOTP (RFC 6238, 2011) replaces the counter with T = floor((Unix time − T0) / X), with T0 = 0 and a time step X of 30 seconds by default, and permits HMAC-SHA-256 and HMAC-SHA-512 as well as SHA-1. Most authenticator apps still use SHA-1, six digits and 30 seconds, which is safe here because HMAC security does not depend on SHA-1 collision resistance.
Verification needs tolerance. HOTP servers use a look-ahead window to resynchronise when a user has pressed the token without logging in; TOTP servers typically accept one time step on either side to allow for clock skew and network delay, and RFC 6238 recommends allowing no more than one step backward. Both need throttling: a six-digit code has only 10^6 values, so without rate limiting an attacker can guess within a validity window, and NIST SP 800-63B requires verifiers to limit consecutive failed attempts. A verifier must also reject reuse of a code that has already been accepted within its window, otherwise a shoulder-surfed or intercepted code can be replayed.
Enrolment is usually a QR code encoding an otpauth:// URI (a de facto format originating with Google Authenticator, not an IETF standard) containing the Base32-encoded secret, issuer, account and parameters. Because the verifier must compute the same HMAC, it stores the secret in recoverable form rather than as a one-way hash; a breach of the seed database compromises every token, as the 2011 attack on RSA's SecurID seeds illustrated. Older schemes include S/KEY (Lamport's hash chain, RFC 1760) and proprietary hardware tokens.
SMS OTP is a different mechanism: the server generates a random code and sends it out-of-band over the telephone network. It inherits that network's weaknesses - SIM-swap fraud, number porting, SS7 interception and malware reading SMS on the device - which is why NIST classifies PSTN delivery as a restricted authenticator. All OTP variants share a structural limitation: the code is a bearer value typed by a human, not bound to the site's origin, so an adversary-in-the-middle phishing page can relay it within its validity window. OTP therefore raises the cost of credential stuffing and password reuse attacks but is not phishing-resistant in the NIST sense, unlike FIDO2/WebAuthn passkeys.
What to learn first
Everything this builds on, foundations first.
- Digital identity
- →Credential
- →Authentication
- →One-time password (OTP)
Relationships
- A kind of
- Authentication factor
- Requires
- Authentication
- Don't confuse with
- Passkey
- Mitigates
- Credential stuffing
Sources & further reading
Standards & official texts
- RFC 6238 - TOTP, Time-Based One-Time Password Algorithm
- NIST SP 800-63B - Digital Identity Guidelines, Authentication and Lifecycle Management
Course material
- Cyber Security Fast Track - Kursuskompendium, Ordliste (MFA - SMS-kode eller app-godkendelse)
Where this data comes from
This entry was drafted by an AI from the sources above and has not yet been checked by a person. Treat it as a starting point, and check anything important against the sources.
See the review queueSuggest a correction on GitHubThis term as JSON
Mentioned in
Check yourself
Loading…