We are using the following methods to create temporary passwords, I am wondering if this is a good practice, since Random is not truly random. Beside the fact that we should generate it with another list of valid characters I highly doubt that this is random enough:
public static string CreatePassword(int length)
{
const string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
StringBuilder res = new StringBuilder();
Random rnd = new Random();
while (0 < length--)
{
res.Append(valid[rnd.Next(valid.Length)]);
}
return res.ToString();
}
Should we add some other randomness e.g. process Id or something similar? Or maybe "new Random" just needs a some kind of salt?
The question I am asking here is more specific, since I am asking about specific problems with the given code I am providing. My question is not how to generate random temporary passwords, but how the code I am providing is problematic and why the answers and suggestions are better in these regards. Maybe I should have posted it in the "Code Reivew" Stack. But I personally do not see it as exact dupblicate of the other question.