Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ryanulit/5a8a57a34df409bec6cf to your computer and use it in GitHub Desktop.
Save ryanulit/5a8a57a34df409bec6cf to your computer and use it in GitHub Desktop.
A sample method to generate a reset token using RNGCryptoServiceProvider instead of a GUID.
public string GenerateResetToken(int length)
{
using (var rng = new RNGCryptoServiceProvider())
{
var bytes = new byte[256];
rng.GetBytes(bytes);
var str = Convert.ToBase64String(bytes);
var rgx = new Regex("[^a-zA-Z0-9]");
str = rgx.Replace(str, "");
return str.Substring(0, length);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment