When a user on our site looses his password and heads off to the Lost Password page we need to give him a new temporary password. I don't really mind how random this is, or if it matches all the "needed" strong password rules, all I want to do is give them a password that they can change later.
The application is a Web application written in C#. so I was thinking of being mean and going for the easy route of using part of a Guid. i.e.
Guid.NewGuid().ToString("d").Substring(1,8)
Suggesstions? thoughts?
Added some supplemental code to the accepted answer. It improves upon answers just using Random and allows for some password options. I also liked some of the options from the KeePass answer but did not want to include the executable in my solution.
This was the first link when I searched for generating random passwords and the following is out of scope for the current question but might be important to consider.
System.Web.Security.Membership.GeneratePassword
is cryptographically secure with a minimum of 20% of the characters being Non-Alphanumeric.validChars can be any construct, but I decided to select based on ascii code ranges removing control chars. In this example, it is a 12 character string.
I don't like the passwords that Membership.GeneratePassword() creates, as they're too ugly and have too many special characters.
This code generates a 10 digit not-too-ugly password.
Sure, I could use a Regex to do all the replaces but this is more readable and maintainable IMO.
There's always
System.Web.Security.Membership.GeneratePassword(int length, int numberOfNonAlphanumericCharacters
).Insert a Timer: timer1, 2 buttons: button1, button2, 1 textBox: textBox1, and a comboBox: comboBox1. Make sure you declare:
Source Code: