Code to generate random password

Niladri.Biswas
Posted by Niladri.Biswas under C# category on | Points: 40 | Views : 686
public static string GeneratePassword()
{
char tmpChar;
int idx;
string password = string.Empty;
string[] charArray = new string[62];

for (idx = 0; idx <= 9; idx++)
{
charArray[idx] = idx.ToString();
}

for (idx = 65; idx <= 90; idx++)
{
tmpChar = (char)idx;
charArray[idx - 55] = tmpChar.ToString();
}

for (idx = 97; idx <= 122; idx++)
{
tmpChar = (char)idx;
charArray[idx - 61] = tmpChar.ToString();
}

Random randomObj = new Random();
for (idx = 0; idx < 8; idx++)
{
password += charArray[randomObj.Next(62)];
}

return password;
}

Comments or Responses

Login to post response