I'm working on a C# project where I need to generate random passwords.
Can anyone provide some code or a high-level approach for password generation?
It should be possible to specify the following:
Avoid weak, commonly used passwords like asd123, password1, or Temp!. Some examples of a strong password include: S&2x4S12nLS1*, JANa@sx3l2&s$, 49915w5$oYmH. Avoid using personal information for your security questions, instead, use LastPass to generate another “password" and store it as the answer to these questions.
you can use this method and modify according to your need
private static string CreateRandomPassword(int passwordLength)
{
string allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789!@$?_-";
char[] chars = new char[passwordLength];
Random rd = new Random();
for (int i = 0; i < passwordLength; i++)
{
chars[i] = allowedChars[rd.Next(0, allowedChars.Length)];
}
return new string(chars);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With