Wednesday, August 11, 2010

Generate Password using C#

public string GeneratePassword()

{
Random rndNumber = null;
        char[] chars = null;
try

{

int passwordLength = 8;

string allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789";
chars = new char[passwordLength];

rndNumber = new Random();

for (int i = 0; i < passwordLength; i++)

{



chars[i] = allowedChars[rndNumber.Next(0, allowedChars.Length)];

}

}

catch

{

throw;

}

return new string(chars);

}

No comments:

Post a Comment