Skip to content

Instantly share code, notes, and snippets.

@DeebiKaaRaviSankar
Created August 19, 2022 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeebiKaaRaviSankar/4da669cf5c0f30e1e372b611d1c2d297 to your computer and use it in GitHub Desktop.
Save DeebiKaaRaviSankar/4da669cf5c0f30e1e372b611d1c2d297 to your computer and use it in GitHub Desktop.
public string GenerateOTP(User user, int OTPLength)
{
string[] AllowedCharacters = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
string OTP = String.Empty;
string sTempChars = String.Empty;
Random rand = new Random();
for (int i = 0; i < OTPLength; i++)
{
int p = rand.Next(0, AllowedCharacters.Length);
sTempChars = AllowedCharacters[rand.Next(0, AllowedCharacters.Length)];
OTP += sTempChars;
}
if (user.EmailValidationToken == OTP)
{
GenerateOTP(user, OTPLength);
}
return OTP;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment