Created
November 23, 2015 15:09
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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