Wednesday, January 26, 2022

How to generate OTP using python | From Dilsecodie




 Let's begin with how to generate OTP code.
Step 1: open dilsecodie website. 

Step 2: Then go to the python section to get top generation code.
 , make changes according to OTP code generation can change range values as per your policy.

Step 3: can use this function in any python project, as it's in working condition otp pin code can be used to send OTP to mobile number for verification purposes.

Security has been a point of concern for the banking industry and one-time password prevents them.
OTP one time password is generated and sent to the user on a mobile number or on an email address.
can use for Secure payments.

This snippets code can be used in backend development.
also, you can save this code in the database then verify the same code entered by the user.

OTP is anything its just SMS scented your way with a security number with it,
which need to enter by the mobile number owner to validate that the user is valid 
or not for that particular service.

Mainly it's very important for financial transactions by the bank when we do debit or card transactions.

Nowadays it's the most important part to very the user is valid or not, so mainly applications send OTP by using a backend algorithm using the SMS gateway provided by some vendor. 

Now about technologies like 
Suppose in the backend we have java.
so we need to write a code using a predefined algorithm.
 firstly need to make a pattern for random number generation 
in a string from like declare string ""
String ="abcdefghijklmnopqurstuvwxyz1234567890";
then we need to start for loop to generate number length 1-4 or 1-6

1t loop for (int i = 1; i <= 1; i++)  look like
Collections.shuffle(letters); so:
letters are string which pass in shuffle method for shuffling purpose 
then ,
again 
for (String letter : letters) { for get shuffled += letter; values from  it 
String otpcode = shuffled.substring(0, num); now num will be length for top , ex : 4, 6 
as per need. 
after the top code generated pass, this code in the send OTP method which is custom logic need to write on your own.
for ex : HttpClient httpClient = HttpClientBuilder.create()
if your using Httpclient class to send SMS to user then this example for you , you can also use other method available in other  programming languages ,
.setSSLContext(new SSLContextBuilder().loadTrustMaterial(null, TrustAllStrategy.INSTANCE).build()) - to avoid SSL issues.
.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build(); 

HttpGet get = new HttpGet(url);
HttpResponse responseHttp = httpClient.execute(get); - execute method is available for you to execute HTTP request.

HttpEntity entity = responseHttp.getEntity();  when we get a response from SMS gateway then that entity needs to validate whether it's a success request or failure request achieved at the user level.

1 comment:

  1. Thank you for sharing this informative and valuable content here.
    Get the awesome coding snippets at
    source code
    Visit for more Education repositories

    ReplyDelete