OTP Login Done Right: Security, Rate Limits, Autofill and SMS vs WhatsApp OTP
Build OTP login that is secure, cheap and pleasant: how OTPs should be generated and stored, rate limiting, SMS pumping fraud, autofill on Android, iOS and the web, and when to use WhatsApp or voice OTP.

Table of contents
How OTP login works

- 1
User enters phone number: your app asks the backend to start a login.
- 2
Server generates the OTP: a random 4–6 digit code, stored as a hash with an expiry time.
- 3
Code is delivered: by SMS, WhatsApp or voice through a provider.
- 4
User submits the code: the server compares it with the stored hash and checks expiry and attempts.
- 5
Session is created: the server issues a session or token and deletes the used OTP.

Security rules that matter
- Random and short-lived: generate with a secure random function; expire in about 5 minutes.
- Store a hash, not the code: so a database leak does not reveal active OTPs.
- Limit attempts: lock after 3–5 wrong entries and require a new OTP.
- One-time use: invalidate after successful verification.
- Same response for unknown numbers: avoid revealing whether a number is registered.
- Log and alert: unusual spikes in OTP requests often indicate an attack.
Stop SMS pumping fraud
SMS pumping (also called toll fraud) happens when bots trigger thousands of OTPs to premium or fake numbers, and you pay for every message. Protect your OTP endpoint with rate limits per number, IP and device; block unexpected countries; add bot protection after a few requests; and set spend alerts with your SMS provider.
Tip: If your app only serves Indian customers, reject non-Indian numbers at the OTP endpoint. It removes most pumping risk immediately.
Make it effortless with autofill
- Android: the SMS Retriever or SMS User Consent API reads the OTP automatically when the message includes your app hash.
- iOS: mark the field as a one-time code so the keyboard suggests the code from Messages.
- Web: use autocomplete="one-time-code" on the input; the WebOTP API can read codes on supported browsers.
- Paste support: let users paste the full code into a split OTP input.
SMS, WhatsApp or voice?
“Offer SMS first, WhatsApp as a one-tap alternative, and voice as the fallback. Users pick what works for them.”
| Channel | Strengths | Watch out for |
|---|---|---|
| SMS | Works on every phone, no app needed | DLT rules, delivery delays, cost per SMS |
| Fast, reliable, copy-code button | User needs WhatsApp; authentication template rates | |
| Voice | Good fallback for feature phones and failures | Slower, can be missed |
Topics
Umer Hasan
Co-Founder & CTO at Zapprex
Leads engineering, cloud infrastructure and AI automation at Zapprex Technologies, with 7+ years of full-stack and mobile experience.
Keep reading
All articlesWeb Application Security Checklist: 25 Must-Do Steps Based on the OWASP Top 10
A practical, plain-English security checklist for websites and web apps: access control, injection, authentication, secrets, dependencies, headers, logging and backups — mapped to the OWASP Top 10.
API Security Best Practices: Authentication, Authorisation, Rate Limiting and More
How to secure REST and GraphQL APIs used by mobile apps and websites: tokens and keys, object-level authorisation, input validation, rate limits, CORS, webhooks and logging — with simple examples.
India’s DPDP Act Explained for App and Website Owners: What You Need to Do
A simple guide to India’s Digital Personal Data Protection Act and Rules: consent and notices, purpose limits, user rights, children’s data, breach reporting, retention and the product changes to plan.
Questions readers ask
Around 5 minutes is a common balance between security and convenience, with a limit of a few verification attempts per code.
For most consumer apps, yes, when combined with rate limits, attempt limits and device checks. High-risk actions such as payments may need additional verification.
Six digits are harder to guess and are standard for sensitive flows. Four digits can be acceptable for low-risk flows with strict attempt limits.
Have a project in mind?
Let's build something that moves your business forward.
Share your idea, process or problem — we will come back with a clear plan, timeline and cost range. No technical spec needed.
- Founder reply within 1 business day
- NDA on request · 100% code ownership
- Talk directly to the engineers
