One-time passwords (OTPs) protect sign-ins, password resets and payments. In Kenya, where almost everyone has a phone but not everyone checks email, SMS is usually the first choice, with email as a backup or for less urgent codes.
This guide covers how to send OTPs well: choosing the channel, designing the code, protecting it and keeping the cost under control.
SMS or email?
- SMS reaches any phone, needs no data and usually arrives in seconds. It is paid per message. Best for sign-in, phone verification and payments.
- Email needs data and an inbox, and can land in spam if your domain is not set up. It costs very little per message. Best for confirming an email address, password resets and as a backup channel.
A practical approach: send the OTP by SMS, and offer "send by email instead" if the SMS does not arrive. Many systems send both for high-value actions such as changing payout details.
Designing the code
- Length: 6 digits is the usual balance between security and ease of typing.
- Random: generate codes with a cryptographically secure random generator, never from the time or the phone number.
- Short expiry: 5 to 10 minutes is common. After that, the user requests a new code.
- One use only: once a code is used, it is gone.
- Store it safely: keep a hash of the code on your server, not the code itself.
Writing the message
Keep it short, clear and safe:
- Put the code near the start so it shows in the phone's notification.
- Name your brand so users know it is genuine.
- Tell users never to share the code; fraudsters often call pretending to be support.
- Avoid emojis: they switch the SMS to Unicode, which holds only 70 characters and can double the cost.
Protecting the OTP flow
- Rate limits: allow only a few code requests per phone number and per IP address in a short time. Without this, attackers can use your form to send thousands of SMS at your expense.
- Attempt limits: lock the code after a few wrong tries.
- Resend timer: make users wait 30 to 60 seconds before they can request another code.
- Bot checks: add basic bot protection to public forms that trigger SMS.
- Logs: record every OTP request (without the code) so you can spot abuse.
Delivery and sender IDs
Use a provider that gives you delivery reports per message, so you know whether a code reached the phone or failed on a network. Sending from a registered sender ID with your business name makes the message more trustworthy than a random number. Ask your provider what is needed to register one.
Sending OTPs by email
Email OTPs should come from your own domain (for example no-reply@yourdomain.co.ke) with SPF, DKIM and DMARC set up, or they will land in spam. Our guide to sending receipts and OTP emails from your own domain explains the setup.
Testing without paying
Before going live, test your flow with test API keys that do not deliver or charge. Check: the code arrives, expiry works, wrong codes are rejected, rate limits trigger and the resend timer works.
What it costs
Each OTP is usually one SMS if the message stays under 160 standard characters. At KES 0.40 per SMS (the JMSURF SMS rate for Kenyan networks), 10,000 sign-in codes a month cost about KES 4,000. Email codes cost far less per message, which is why email works well as a backup.
JMSURF SMS and JMSURF Mail for OTPs
JMSURF SMS has a REST API for single and bulk sends, delivery status, signed webhooks and free test keys (jms_test_) that never charge or deliver. Kenyan SMS cost KES 0.40 per 160-character message, prepaid by M-Pesa or card, with no subscription.
JMSURF Mail is a transactional email API that sends from your own domain with DKIM signing, delivery logs, webhooks and an optional SMS in the same call through JMSURF SMS. Plans start free (100 emails a month) and paid plans start at KES 499 a month.
Frequently asked questions
How long should an OTP code be?
Six digits is the common choice. It is easy to type and, with a short expiry and attempt limits, secure enough for most sign-ins.
How long should an OTP be valid?
Five to ten minutes is typical. Shorter is safer; longer causes fewer support calls. Always make codes single-use.
Why are my OTP SMS not arriving?
Check the delivery report for the message. Common causes are wrong number formats, numbers that are switched off, network delays or sending from an unregistered sender ID.
Is it cheaper to send OTPs by email?
Yes, per message. But not everyone checks email quickly, so most Kenyan apps use SMS first and email as a backup.
How do I stop people abusing my OTP form?
Add rate limits per number and IP, a resend timer, attempt limits and basic bot protection, and watch your logs for spikes.
