Send OTP on Mobile using Python

Ashish Pratap Singh
2 min readJul 2, 2020

--

OTP (One-Time Password) is a technical term through which we can generate a single-use password and sent it to the provided mobile number to access the Application. It is also known as two-factor authentication. … OTP lends an additional layer of security to protect the digital identity of the end-users.

Nowadays, every people in the world has a mobile phone, and developers commonly need to use user's phone numbers and send OTP on their device through which users get access to use Applications.

currently, there are several ways to verify the user’s phone numbers, but a randomly generated one-time password (OTP) sent by SMS is one of the most common. Sending this code back to the developer’s server demonstrates control of the phone number.

OTP demo, how it looks like

I’m not going to waste your precious time, So directly I’m telling you what needs to send a random generated OTP on the user's mobile number.

I’m going to introduce a service provider web application which helps us to send OTP on the mobile phone that is Twilio.
Twilio is a super service provider, it enables you to send a message or OTP on the user's device.

https://www.twilio.com/login
Twilio

First:
You need to create an account on Twilio with your email and 14 digit password, after that it demands your mobile number then you’ll get an OTP on your device.
login in Twilio with your email id and 14 digit password it’ll ask you to generate a free trial number you can choose and generate it or you can purchase its services.

Second: Twilio provide account_session_id and auth_token that interact with python, which is going to use in our code.

Data flow

Third: For python, you need to install twilio, you can do this by using
pip install twilio

Fourth: From twilio get your account_sid and auth_token which is used by twilio Client module like:
client = Client(account_sid, auth_token)

Fifth: now you write python code and type your message in the body section and run the code. it will provide you a massage session-id which indicates that message successfully sent to the user mobile number.

You’ll get my code from GitHub
Thanks for coming here.

--

--

No responses yet