Created
September 22, 2016 23:35
-
-
Save BryanWilhite/efa3a1e72902ae2f23d19c681cd99f15 to your computer and use it in GitHub Desktop.
This file contains 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
using System; | |
namespace Cetera.Security | |
{ | |
/// <summary> | |
/// Password utilities. | |
/// </summary> | |
public static class PasswordUtility | |
{ | |
/// <summary> | |
/// Generates the random password. | |
/// </summary> | |
/// <param name="passwordLength">Length of the password.</param> | |
/// <param name="seed">The seed.</param> | |
/// <returns></returns> | |
/// <remarks> | |
/// For more details, see “Generate random password in C#” by Mads Kristensen | |
/// [http://madskristensen.net/post/Generate-random-password-in-C] | |
/// </remarks> | |
public static string GenerateRandomPassword(int passwordLength, int seed) | |
{ | |
var allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789!@$?_-"; | |
var chars = new char[passwordLength]; | |
var r = new Random(seed); | |
for (int i = 0; i < passwordLength; i++) | |
{ | |
chars[i] = allowedChars[r.Next(0, allowedChars.Length)]; | |
} | |
return new string(chars); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment