1. Overview
This document talks about how to generate OTP & Integration of SMS.
2. Technologies and Tools Used
The following technologies has been used to Integrating SMS & generating SMS.
Ø MS SQL Server
Ø DotNet & Angular
3. Use Case
Assume that there is a requirement to generate OTP & Send SMS to Respective Person.
4. Architecture
Following steps explains in detail,
Step 1: It validates and generate OTP , It allows to generate New OTP Maximum 3 times and resend OTP Maximum 5 Times. It is not allowed Maximum of OTP.
This Query for generating OTP.
SELECT CAST(1000000-CEILING(RAND()*899003)+DATEPART(MS, GETDATE()) AS INT)
Step 2: Generating OTP and insert OTP into table.
BEGIN
SET NOCOUNT ON;
DECLARE @EmployeeReferralID int;
DECLARE @OTP varchar(6);
DECLARE @CurrentDatetimeIST datetime=(SELECT (GETDATE() as TIME ZONE ‘Eastern Standard Time’) AT TIME ZONE ‘India Standard Time’);
SELECT @OTP= CAST(1000000-CEILING(RAND()*899003)+DATEPART(MS, GETDATE()) AS INT)
END
Step 3: Verify OTP for respective Mobile Number.
BEGIN
DECLARE @OTPInput varchar(6);
DECLARE @OTP varchar(6);
SELECT @OTP=top 1 otp from tblemployeeOTP where mobileno=@mobileno order by desc;
if(@OTPInput=@OTP)
BEGIN
SELECT ‘OTP Verified’;
END
ELSE
BEGIN
SELECT ‘OTP is Wrong’;
END
END
Step 4: Resend OTP: First we need to check whether this number is available . After that need to check how many attempt tried and how many otp wrong. After that we need to send OTP
BEGIN
if(@attempt>4 and @OTPCount>0)
BEGIN
SELECT @OTP= CAST(1000000-CEILING(RAND()*899003)+DATEPART(MS, GETDATE()) AS INT)
END
ELSE
BEGIN
SELECT ‘Your OTP count execeed limt’
END
END
Step 5: Integration of SMS: we need to provide provider API information and mobile number.
We need to provide the sender id , SMS text and credentials.
1 // use the API URL here
2 string strUrl = “http://api.mVaayoo.com/mvaayooapi/MessageCompose?user=YourUserName:YourPassword&senderID=YourSenderID& receipientno=1234567890&msgtxt=This is a test from mVaayoo API&state=4”;
3 // Create a request object
4 WebRequest request = HttpWebRequest.Create(strUrl);
5 // Get the response back
6 HttpWebResponse response = (HttpWebResponse)request.GetResponse();
7 Stream s = (Stream)response.GetResponseStream();
8 StreamReader readStream = new StreamReader(s);
9 string dataString = readStream.ReadToEnd();
10 response.Close();
11 s.Close();
12 readStream.Close();
5. Conclusion
Generate OTP & Verify OTP through back end is best way to handle OTP. We can validate and configure easy way .