Den här metoden slumpar fram ett lösenord.
string CreatePassword(int length) {
const string chars = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789";
StringBuilder result = new StringBuilder(length);
Random rnd = new Random();
while (length-- > 0) {
result.Append(chars[rnd.Next(chars.Length)]);
}
return result.ToString();
}
Exempel:
string password = CreatePassword(5);