Then there's the holy grail, which was too much for the requirements I was working with, eight alphanumeric digits only. Simplicity is divine.
private Random m_random = new Random();
public string CreateRandomPassword(int length)
{
char[] chars = new char[length];
int index = 0;
while (index < length)
{
char c = (char)m_random.Next(48, 122);
if (Char.IsLetterOrDigit(c))
{
chars[index] = c;
index++;
}
}
return new string(chars);
}
No comments:
Post a Comment