Sorry for my silly question. I am very new to learning c#. Right now i wanted to generate 5 random password for my assigment. After i finish my code, i notice that it generate 5 password but those 5 password are the same. i wanted those password to be different from one another.
Here is my code :
static void Main(string[] args)
{
int length = 7;
int i, n = 5;
for (i = 0; i < n; i++)
{
string pass = CreateRandomPassword(length);
Console.WriteLine("Password: " + pass);
}
Console.ReadLine();
}
private static string CreateRandomPassword(int length)
{
string validChars = "ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@$#?%&";
Random random = new Random();
char[] chars = new char[length];
for (int i = 0; i < length; i++)
{
chars[i] = validChars[random.Next(0, validChars.Length)];
}
return new string(chars);
}
}
}
The output it produce : Password: MBZAW09 Password: MBZAW09 Password: MBZAW09 Password: MBZAW09 Password: MBZAW09
i want the output to be like this : Password: MBZAW09 Password: edr$#c9 Password: 167&uj@ Password: @&dfy71 Password: 1gr6%8u
Can anyone help me out ???