An OTP is only useful if the person receives it and can use it quickly. Most problems come from the message and the flow around it, not the code itself. This guide covers the message, the code, the flow and the security side, with the reasoning behind each habit.
The message
- Put the code first, so it shows in the notification preview
- State the expiry in the message
- Add a short do-not-share warning
- Name the product, so the user knows what the code is for
- Use a registered transactional template, never a promotional one
- Keep it to one segment, and leave out links and offers
A clear example: “482915 is your OTP for Acme. It expires in 10 minutes. Do not share it with anyone.” The code is visible without opening the message, the purpose is clear, and the warning protects the user from the most common scam.
Designing the code
- Use a cryptographically secure random generator, not a counter or a timestamp
- Six digits is common; shorter codes are easier to guess and longer ones are harder to type
- Make each code single-use and invalidate it once verified
- Expire codes after a few minutes
- Store only a hash of the code on your side, and never write the code to logs
Resend and fallback flows
- Let people request a resend, with a short wait before it unlocks
- Use the delivery report to decide when to offer another channel such as voice
- Invalidate the earlier code when a new one is issued, or accept only the latest
- Show clear, calm messages when a code expires instead of a generic error
The delivery report is the signal that makes this work. If it says delivered, the user probably has the code and a resend only adds confusion. If it says failed or never arrives, offer a voice call. Our guide to delivery reports explains each status.
Preventing abuse
An open OTP endpoint can be used to send large numbers of messages to numbers the attacker chooses, which costs you money and annoys real people. Defend it in layers.
- Limit attempts and resends per number to stop abuse
- Rate-limit by IP address, device and account as well as by number
- Add a challenge, such as a CAPTCHA, before sending to a new number
- Watch the ratio of codes requested to codes verified, and alert when it drops
- Cap spend per day and alert on unusual destinations
Autofill and usability
Both Android and iOS can offer to fill a code from an incoming message when the message follows the platform’s guidelines, which removes typing and reduces errors. Check the current platform documentation for the exact format, and keep the code and the product name in a predictable place in the text. Allow users to paste a code, and accept codes with a space or hyphen in them.
Security limits of SMS OTP
SMS is convenient but not the strongest second factor. Messages can be intercepted in some situations, and attackers can take over a number through a SIM swap. For high-risk actions such as large transfers or changing recovery details, offer a stronger option such as an authenticator app or a hardware key, and treat the SMS code as one signal among several rather than as proof by itself. None of this depends on a particular provider. It is good practice for any OTP flow.
Voice as a fallback
A spoken OTP helps when an SMS does not arrive, when the user is on a landline-like connection, or when text is hard for them to read. Offer it after a short wait rather than immediately, read the digits slowly with a pause between them, and repeat the code once. Treat the voice code with the same expiry, attempt limits and rate limits as the SMS code, since the call can be abused in the same way. Our voice API and IVR service covers how this is set up.
Language and localisation
Users are more comfortable verifying in their own language, but remember that regional-language text uses Unicode and fits fewer characters per segment. Register a separate template for each language, keep the code and expiry in the same position in each, and test the final text on real phones. Our SMS segments guide explains the limits.
A launch checklist
- Template approved on DLT and tested on handsets from at least two operators
- Codes are random, single-use and expire within minutes
- Resend delay, attempt limits and rate limits are switched on
- Delivery reports are stored against each request
- A fallback channel is ready for messages that are not confirmed
- An alert fires when the verification rate drops
Testing and monitoring
Test with real handsets on more than one operator before launch, including a phone in a poor coverage area, and measure the time from request to receipt. In production, track delivery time, failures by operator and verification success rate. Our bulk SMS and OTP gateway page explains the delivery side, and the promotional versus transactional guide covers why OTPs must never share a template category with offers.