private string GenerateRandomPassword(int Length)
{
// We want all popular characters except for the ones that can easily be confused (e.g., l and 1)
string[] Characters = new string[56];
Characters[0] = "a";
Characters[1] = "b";
Characters[2] = "c";
Characters[3] = "d";
Characters[4] = "e";
Characters[5] = "f";
Characters[6] = "g";
Characters[7] = "h";
Characters[8] = "j";
Characters[9] = "k";
Characters[10] = "m";
Characters[11] = "n";
Characters[12] = "p";
Characters[13] = "q";
Characters[14] = "r";
Characters[15] = "s";
Characters[16] = "t";
Characters[17] = "u";
Characters[18] = "v";
Characters[19] = "w";
Characters[20] = "x";
Characters[21] = "y";
Characters[22] = "z";
Characters[23] = "A";
Characters[24] = "B";
Characters[25] = "C";
Characters[26] = "D";
Characters[27] = "E";
Characters[28] = "F";
Characters[29] = "G";
Characters[30] = "H";
Characters[31] = "J";
Characters[32] = "K";
Characters[33] = "L";
Characters[34] = "M";
Characters[35] = "N";
Characters[36] = "P";
Characters[37] = "Q";
Characters[38] = "R";
Characters[39] = "S";
Characters[40] = "T";
Characters[41] = "U";
Characters[42] = "V";
Characters[43] = "W";
Characters[44] = "X";
Characters[45] = "Y";
Characters[46] = "Z";
Characters[47] = "2";
Characters[48] = "3";
Characters[49] = "4";
Characters[50] = "5";
Characters[51] = "6";
Characters[52] = "7";
Characters[53] = "8";
Characters[54] = "9";
Random RandChar = new Random();
string Password = "";
for (int i = 0; i < Length; i++)
{
Password += Characters[RandChar.Next(0, 55)];
}
return Password;
}
No comments:
Post a Comment