Cloud, DevOps & Security 9 min read

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.

Umer Hasan

Umer Hasan

Co-Founder & CTO at Zapprex

OTP Login Done Right: Security, Rate Limits, Autofill and SMS vs WhatsApp OTP
Table of contents

How OTP login works

How OTP login works: 5 steps
  1. 1

    User enters phone number: your app asks the backend to start a login.

  2. 2

    Server generates the OTP: a random 4–6 digit code, stored as a hash with an expiry time.

  3. 3

    Code is delivered: by SMS, WhatsApp or voice through a provider.

  4. 4

    User submits the code: the server compares it with the stored hash and checks expiry and attempts.

  5. 5

    Session is created: the server issues a session or token and deletes the used OTP.

At a glance: Security rules that matter — Random and short-lived, Store a hash, not the code, Limit attempts, One-time use
At a glance: Security rules that matter

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.”

— Umer Hasan, CTO
ChannelStrengthsWatch out for
SMSWorks on every phone, no app neededDLT rules, delivery delays, cost per SMS
WhatsAppFast, reliable, copy-code buttonUser needs WhatsApp; authentication template rates
VoiceGood fallback for feature phones and failuresSlower, can be missed

Topics

OTP LoginAuthenticationApp SecuritySMS Fraud
Umer Hasan
Written by

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.

FAQ

Questions readers ask

Around 5 minutes is a common balance between security and convenience, with a limit of a few verification attempts per code.

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