One-Time Password
What Is a One-Time Password?
A one-time password, or OTP, is a temporary code used once to confirm a login, account recovery, device verification, or sensitive transaction. It expires quickly or becomes invalid after use, reducing the value of a stolen code.
How OTP Authentication Works
An application creates, delivers, and verifies the code without allowing reuse.
- The user starts a sign-in or verification request.
- The server generates a random code or calculates one from a shared secret and time or counter.
- The app stores validation data, including expiry and allowed attempts.
- The code appears in an authenticator app or is sent by SMS, email, or voice.
- The user enters the code, and the server compares it with the expected value.
- The server accepts it once, then invalidates it after use or expiry.
Types of One-Time Passwords and Delivery Methods
Generation schemes and delivery channels differ. TOTP and HOTP define how a code is calculated, while SMS and email describe how a server-generated code reaches the user.
| Type or channel | How it works | Key consideration |
|---|---|---|
| TOTP | An authenticator app calculates a code from time and a shared secret. | Works offline after setup but requires accurate device time. |
| HOTP | A code is calculated from a shared secret and increasing counter. | Can fall out of sync if codes are generated but unused. |
| SMS, email, or voice | A server creates and sends a code through a communication channel. | Convenient, but security and delivery reliability vary. |
Benefits of One-Time Passwords
OTPs add a temporary check to authentication flows.
- A captured code cannot normally be reused after acceptance or expiry.
- Short validity periods limit the window for misuse.
- They can provide a second factor alongside a password.
- They support step-up verification before resetting credentials or adding a payment method.
Limits and Security Risks of OTPs
An OTP proves access to a channel or authenticator, not necessarily the user's identity.
- Phishing sites can relay a valid code to a real service in real time.
- SMS codes can be exposed through SIM-swapping, and email codes fail if the inbox is compromised.
- Delayed messages can frustrate users and cause retries.
- Unlimited guesses or resend requests can enable abuse.
- Code-only flows can create barriers for people without reliable phone or email access.
How to Implement OTPs Safely in an App
Secure implementation matters as much as the code. MDN provides guidance on OTP authentication security.
- Use short expirations, strict attempt limits, and single-use invalidation.
- Rate-limit requests and retries, using exponential backoff where appropriate.
- Store server-generated codes in hashed form when practical.
- Log verification events without recording the code.
- Provide clear error messages and a secure recovery path.
- Offer passkeys for phishing-resistant authentication when stronger assurance is needed.
One-Time Passwords in Apps Built With Emergent
When building with an AI app builder, define when an OTP is required, how the backend validates it, and which provider sends it. Test expired codes, duplicate submissions, resend limits, and provider outages before deployment. Monitoring API uptime helps detect delivery failures that block sign-ins.
on Emergent today

