Where Phone Verification Breaks and How to Test It

|Author: QUASA Editorial Team|6 min read| 1
Where Phone Verification Breaks and How to Test It

A team decides to ship their app to a new geography. The number of installs grow, marketing is happy. But something starts slipping in the sign up flow. Maybe the code takes too long to arrive, gets filtered by the carrier or never even left the sms provider. Your users will click resend 3 times and give up.

There are many reasons phone numbers have been overlooked when it comes to building mobile apps. So lets trace a single code from click to your database and see where things can fail.

The Request Looks Simple Until It Isn't

Begin with the number. They will enter it however they like: with spaces, dashes, brackets, or a leading zero when the country code makes it redundant. You want to make sure all phone numbers are converted to the E.164 standard before you store it or pass it on to an sms service. Format: + [Country Code] [Subscriber Number] (max 15 digits).

Limit your endpoints. There will be bots out there hitting your form to send messages and you are paying for those. Limit the number of requests to that number, device id, IP and implement a time period between sends. Keep CAPTCHA or device checks for suspicious traffic so honest users never see them.

Provide a country selection dropdown that defaults to what they most likely need and a mask that doesn't fight the user's typing. Test submitting numbers with spaces, a leading zero, and an incorrect country code, and confirm that what gets stored is always clean E.164.

The Message Leaves Your Server. Then What?

Your API returned 200. All that tells you is that the message made it to the SMS gateway. There could be aggregators or phone carriers between that and the end user. Your code could be stuck anywhere. 

You should be collecting DLRs. You can build reports on delivery rates and time-to-deliver for different countries/carriers. Set up alerts for when a route degrades, or if you notice a route taking longer than usual, it's worth investigating.

Certain countries may require additional steps. India has required you to register your sending ID and message templates through their DLTs. In the US if you're texting from local numbers you will most likely need to register for A2P 10DLC. Always double check with your provider what is currently required.

Testing the Flow Without Using Your Own SIM

OTP authentication is awkward to test. Personal numbers don't belong on staging, shared test accounts hit rate limits within a day, and QA can't hold SIM cards for twelve countries.

Some teams keep a small pool of virtual numbers for staging; an sms verification number from a temporary-number service is one example of that class of utility. Others lean on the provider's sandbox or mock mode, or on test numbers that accept a preset code on your staging environment. Whatever you pick, automate it with end-to-end tests, and give resend, code expiry, wrong input, and the attempt to limit their own cases.

Only have temporary and virtual phone numbers for dummy accounts that contain no information and or funds. Do not use them to auth users on their actual account. Always follow each 3rd party's terms.

Ten Seconds on the User's Screen

Your user will give the verification code about 10 seconds of their life. Do not waste those 10 seconds. 

Web/iOS should have autocomplete="one-time-code" on the input field so you can display it on the keyboard. Chrome/android will also parse SMS messages with the WebOTP api as long as it ends with "@yourdomain.com #123456". If your app is native android you can use the SMS Retriever API which does not require sms permissions but will expect an app hash at the end of your sms.

Most are 6 digits long. You could go with 4, it's easier to enter and remember. Expire codes quickly, limit tries and tell the user they can resend with a timer.

Tell the user why and what they need to do. "Code has expired please use this new code" is better than "Invalid." Ensure inputs are thumb friendly and accessible to blind users. Auto advancing digits are key when dealing with Flutter/React Native form fields. You'll run into issues with pasting and auto fill here. Make sure you receive a code when you're on a physical iPhone and Android device. The user should not have to manually enter it.

What Happens to the Number Afterward

Phone numbers can identify someone so keep them in mind. Only gather them if you need to, limit who can read them, and mask them in logs and support tools. And make sure your logging systems or helpdesk redact them. Be aware of privacy laws in your target audience area.

Verification codes should also be treated with caution. Do not store them in any form that is plaintext. Salted hash and expire once used then remove. Many developers will want to load their testing environments with live data to test quickly. Do not do this. Use dummy data to create users and phones.

SMS is great but knows it has limitations. SIM-swap fraud and message interception are real risks. In NIST SP 800-63B-4 they label Out of band Authentication using the phone network as a restricted authenticator. You can use it but there are things to consider. Consider having pass keys or TOTP and Push notification methods available to your users. There are still many benefits of using SMS for two factor authentication. Just remember it's not your most secure form of auth.

A Short Checklist

Make sure you have each number as an E.164 before shipping. Have delivery status tracked for each carrier and country and if any region requires a sender ID or template to be approved make sure they are. Failures from carriers silently dropping messages and statuses being marked delivered will go unnoticed.

Verify the user experience. Be able to test this in your CI pipeline without using SIM cards. Auto fill should work and users should be able to resend the code within the time frame. There should never be any codes or users full phone numbers in your logs. Debug where it's failing and you won't lose users to phone authentication.

Share:

Subscribe to our newsletter

Get the latest Web3, AI, and crypto news delivered straight to your inbox.

0