posted on Sunday, August 15, 2004 9:33 PM
by
warstar
C# password generator function
Here is a password generator:
public static string CreateRandomPassword(int PasswordLength)
{
string _allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789!@$?";
Byte[] randomBytes = new Byte[PasswordLength];
char[] chars = new char[PasswordLength];
int allowedCharCount = _allowedChars.Length;
for(int i = 0;i<PasswordLength;i++)
{
chars[i] = _allowedChars[(int)randomBytes[i] % allowedCharCount];
}
return new string(chars);
}
Happy netting,
warnar