Skip to content

Instantly share code, notes, and snippets.

@haroldcris
Created September 20, 2018 03:32
Show Gist options
  • Select an option

  • Save haroldcris/951a588d87ea34e84adc9e973e5c2ba5 to your computer and use it in GitHub Desktop.

Select an option

Save haroldcris/951a588d87ea34e84adc9e973e5c2ba5 to your computer and use it in GitHub Desktop.
private static string GenerateRandomOtp(int iOTPLength)
{
string[] saAllowedCharacters = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
string sOTP = String.Empty;
string sTempChars = String.Empty;
Random rand = new Random();
for (int i = 0; i < iOTPLength; i++)
{
int p = rand.Next(0, saAllowedCharacters.Length);
sTempChars = saAllowedCharacters[rand.Next(0, saAllowedCharacters.Length)];
sOTP += sTempChars;
}
return sOTP;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment