A one-time password is only as safe as the system around it. Delivery is VerifyWay's job; creating, storing and checking the code is yours. These are the practices that matter most, whatever channel you use.
1. Create codes the right way
- Use a secure random generator, such as
random_int()in PHP orcrypto.randomInt()in Node.js. Never use the current time or a simple counter. - 6 digits is a good default. It balances security and typing. Use 4 to 8 digits if you enable Telegram or fallback, because Telegram accepts only that length.
- Send the code as a string, so a code like
012345keeps its leading zero.
2. Store and check codes safely
- Store a hash of the code, not the code itself, together with the phone number and an expiry time.
- Keep codes short-lived: 5 to 10 minutes is typical. Your app decides how long a code stays valid.
- One use only. Delete or invalidate the code as soon as it is entered correctly.
- Compare in constant time (for example
hash_equals()orcrypto.timingSafeEqual()). - Never log full codes, in your app or in error reports.
3. Limit attempts and resends
| Limit | Suggested value | Why |
|---|---|---|
| Wrong attempts per code | 5 | Stops guessing |
| Resend cooldown | 30 seconds | VerifyWay allows one code per number every 30 seconds |
| Codes per number per day | 5 to 10 | Stops abuse of one number |
| Codes per IP or device per hour | Your choice | Stops bots trying many numbers |
Show a countdown before the "Resend" button, so users do not hit the limit by accident.
4. Protect the send button
- Only allow countries you serve. Codes to unexpected countries are a common sign of abuse.
- Add a bot check (for example a CAPTCHA) before sending, at least after the first resend.
- Watch your conversion rate: codes entered correctly divided by codes sent. A sudden drop usually means bots.
VerifyWay adds its own layer: you pay only for delivered codes, and an account pauses for a short time when its traffic suddenly spreads to many countries or many codes fail. Read more in how to stop OTP fraud.
5. Send reliably
- Keep the API key on your server. Never put it in a mobile app or browser code.
- Use an
Idempotency-Key. After a timeout, repeat the same request with the same key, so the user does not get two different codes. - Turn on fallback with
"fallback": "yes", so users without WhatsApp get the code on Telegram, or the other way round. - Listen to your webhook. If the status is
failed, tell the user right away instead of letting them wait.
curl -X POST 'https://api.verifyway.com/api/v1' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: login-7f3a9c' \
-d '{
"recipient": "+9647701234567",
"type": "otp",
"channel": "whatsapp",
"fallback": "yes",
"code": "482916"
}'
6. Make it easy for users
- Say where the code will arrive: "We sent a code to your WhatsApp" or "on WhatsApp or Telegram".
- Show the number the code went to, with a "Change number" link.
- Use a numeric input (
inputmode="numeric",autocomplete="one-time-code") so phones offer the right keyboard. - Accept pasted codes with spaces removed; WhatsApp users often tap the copy button and paste.
Checklist
| Practice | Done by |
|---|---|
| Secure random code, stored as a hash, short expiry, one use | Your app |
| Attempt limits, resend cooldown, bot check, country allowlist | Your app |
| One code per number every 30 seconds | VerifyWay |
| Delivery, fallback, refunds for failed attempts, delivery webhooks | VerifyWay |
| Short automatic pause on unusual traffic | VerifyWay |
Frequently asked questions
Does VerifyWay create or check the code?
No. Your server creates the code, sends it through VerifyWay and checks what the user types. That keeps verification fully under your control.
How long should a code be valid?
Usually 5 to 10 minutes. Longer gives attackers more time; shorter frustrates users on slow connections.
Should I use 4 or 6 digits?
6 digits for most apps. 4 digits is easier to type but needs stricter attempt limits.
Put these practices to workCreate an account, top up from $10 and send your first code in minutes.Create account