Function for Creating Passwords

One of the things most of us have to do at one point or another, is generate a random password. I once thought this was a daunting task, however found some code at some point or another that gave me great headway into creating a good password generator.

 

private static string CreatePassword(int lengthOfPassword)
{
string[] characters = new string[32] {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "2", "3", "4", "5", "6", "7", "8", "9"}; string password = "";
Random rnd = new Random();
while(password.Length < lengthofpassword)
{
// choose a random character from the array and add it to the password
password +="" characters[rnd.next(36)];
}

// return the generated password
return password;
}

Now, this won't create the best darn password out there, but its a great quick & dirty way of creating a dynamic password for your website.

7 Comments

Comments have been disabled for this content.