Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to create aadhar authentication application .net so i want ask how to generate otp request for aadhar authentication

What I have tried:

i have already tried in wcf,jquery but not result found
Posted
Updated 2-Mar-19 16:49pm

Check below code may be this will help you.
C#
public static string TOTPGenerator(string uniqueIdentity)
{
string oneTimePassword = "";
DateTime dateTime = DateTime.Now;
string _strParsedReqNo = dateTime.Day.ToString();
_strParsedReqNo = _strParsedReqNo + dateTime.Month.ToString();
_strParsedReqNo = _strParsedReqNo + dateTime.Year.ToString();
_strParsedReqNo = _strParsedReqNo + dateTime.Hour.ToString();
_strParsedReqNo = _strParsedReqNo + dateTime.Minute.ToString();
_strParsedReqNo = _strParsedReqNo + dateTime.Second.ToString();
_strParsedReqNo = _strParsedReqNo + dateTime.Millisecond.ToString();
_strParsedReqNo = _strParsedReqNo + uniqueCustomerIdentity;
//Append above string with Policy number to get desired output.
Console.WriteLine("TOTP value: " + _strParsedReqNo);
using (MD5 md5 = MD5.Create())
{
//Get hash code of entered request id in byte format.
byte[] _reqByte = md5.ComputeHash(Encoding.UTF8.GetBytes(_strParsedReqNo));
//convert byte array to integer.
int _parsedReqNo = BitConverter.ToInt32(_reqByte, 0);
string _strParsedReqId = Math.Abs(_parsedReqNo).ToString();
//Check if length of hash code is less than 9.
//If so, then prepend multiple zeros upto the length becomes atleast 9 characters.
if (_strParsedReqId.Length < 9)
{
StringBuilder sb = new StringBuilder(_strParsedReqId);
for (int k = 0; k < (9 - _strParsedReqId.Length); k++)
{
sb.Insert(0, '0');
}
_strParsedReqId = sb.ToString();
}
oneTimePassword = _strParsedReqId;
}
//Adding random letters to the OTP.
StringBuilder builder = new StringBuilder();
Random random = new Random();
string randomString = "";
for (int i = 0; i < 4; i++)
{
randomString += Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
}
//Deciding number of characters in OTP.
Random ran = new Random();
int randomNumber = ran.Next(2, 5);
Random num = new Random();
//Form alphanumeric OTP and rearrange it reandomly.
string otpString = randomString.Substring(0, randomNumber);
otpString += oneTimePassword.Substring(0, 7 - randomNumber);
oneTimePassword = new string(otpString.ToCharArray().OrderBy(s => (num.Next(2) % 2) == 0).ToArray());
return oneTimePassword;
}
 
Share this answer
 
Hello,

Hers is a Very Good Article[^] on OTP available right on this site.

Regards,
Prasad Khandekar
 
Share this answer
 
If and only if you are talking about a One Time Pad:

That "Very Good Article" is wrong. It does not describe a One Time Pad.

For an OTP:
It is a very simple process. Two users have a pad with a variety of encodings listed in it. The two pads match. They chose a new encoding each and EVERY time that they communicate. They never use the same encoding two times in a row. It is that simple. The pads can be in writing, or on a computer that has no wifi capability and no network connection, etc. If you are using a computer that has UEFI on it anywhere, then you are defeating the purpose of typing in the pad entry: You must encrypt seperately then input the encrypted into the computer.

There is nothing more to it.

Look up OTP, One Time Pad.

See: https://en.wikipedia.org/wiki/One-time_pad ,

Quote:
In cryptography, the one-time pad (OTP) is an encryption technique that cannot be cracked, but requires the use of a single-use pre-shared key.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900