OTP & verification
Passwordless Login with Phone OTP: An Implementation Guide
How to build phone-number login without passwords: the flow, backend endpoints, sessions, account recovery, abuse protection, and UX that converts.
In many markets, users are more comfortable typing their phone number than creating a password. Passwordless login with a one-time code removes forgotten passwords, weak passwords, and password reuse in one move. Here is how to build it well.
The flow
- User enters their phone number.
- Backend sends a one-time code by SMS (or WhatsApp).
- User enters the code.
- Backend verifies it and creates a session.
That is the whole experience. The work is in the details behind each step.
Backend endpoints
POST /auth/otp/send with { phone }:
- Normalize the number to E.164 and validate it. See E.164 validation.
- Apply rate limits per number, IP, and device.
- If the number belongs to an active user, generate a code, store its hash with expiry and attempt counter, and send it.
- Return the same response whether or not the number is registered. Otherwise attackers can discover which numbers have accounts.
POST /auth/otp/verify with { phone, code }:
- Look up the stored hash, check expiry and attempts, compare in constant time.
- On success, delete the code, create the session (access and refresh tokens or a secure cookie), and return the user.
- On failure, increment the attempt counter and return a clear error.
Signup and login in one flow
You can merge signup and login: if the verified number has no account, continue to a short profile step. If you keep them separate, send the first code automatically at signup and take the user straight to the code screen. Making them request a second code on a login page wastes a message and a moment of attention.
Sessions
Without passwords, the session is your main protection:
- Use short-lived access tokens with refresh tokens, or secure, HTTP-only cookies.
- Let users see and revoke active sessions.
- Re-verify with a fresh code before sensitive actions, such as changing the phone number.
Account recovery
The hardest case: the user lost access to their number. Plan for it from day one:
- Collect a verified email as a secondary contact.
- Allow changing the phone number only from a logged-in session, with verification of both the old and the new number when possible.
- Provide a support process with identity checks for users who lost both.
UX details that raise conversion
- Default the country code from the user's location, and accept local formats.
- Autofocus the phone field, and the code field on the next screen.
- Support autofill; see OTP autofill on iOS and Android.
- Auto-submit when the last digit is entered.
- Show the number the code was sent to, with a "Use a different number" link.
- Offer resend after a short cooldown and a second channel. See designing the OTP resend flow.
Security and abuse
- Strict rate limits and attempt limits; see OTP best practices.
- Protection against SMS pumping.
- Stronger options for high-risk accounts; see OTP security and SIM swap.
Choosing delivery
Your login is only as good as code delivery in your users' countries. Test delivery times on real networks before launch, and keep a second channel ready. See how to choose a phone verification API.