Search code examples
androidauthenticationsms-verification

How to verify a phone number using a SMS?


I thought of the following scheme, but it would be helpful if someone who has implemented something like this could comment on it:

  1. The user provides his telephone number. The client sends this number together through a HTTPS request.
  2. The server generates a random code which is stored in a DB together with the user's phone number and a deadline. A SMS is sent to the phone number with this random code.
  3. The user receives the SMS and provides the code to the Android client, which in turn sends it to the server again through HTTPS.
  4. The server receives the code and if it is the same and is still within the deadline, it generates a token for the user witch is included in the HTTPS response.
  5. The client stores this token in SharedPreferences and sends it each time she wants to communicate with the server.

Solution

  • Well that's how giants like Whatsapp and Telegram works.

    So I guess this idea is pretty good. You can think about the HTTPS part: http as a whole is rather an heavy protocol; so might be a good idea using another, lees heavy, transmission protocol like MQTT.