Introduction
This program generates random passwords. They may include chars from "A" to "Z", "a" to "z", "0" to 9" and the symbols "!"#$%&$()*+,-./". If you choose you can receive the hash of the password to store the hash and give the user the real password. To use this class in your program, you only need to copy the "public class PasswordGenerator" to your own code.
Thanks for the tip/help to my friend Tiago.
The code is quite simple. To generate password or passwords for your site just use the class like this:
PasswordGenerator p = new PasswordGenerator();
string[] pass = p.Generate(8, true, true, true, 2,true);
Console.WriteLine("{0} = {1}", pass[0],pass[1]);
System.Threading.Thread.Sleep(15)
is really necessary if you dont want the passwords to be all the same. The Random() function needs it.
Check down bellow in the console app how to use this class in your own programs.
string ans = Console.ReadLine();
string mySavedHash = "5D61F65D654D3ADE50FED6EE145F0DE9A157C80C";
string strUser = FormsAuthentication.HashPasswordForStoringInConfigFile(ans, "sha1");
if (strUser == mySavedHash)
{
Console.WriteLine("Ok, nice job.");
}
else
{
Console.WriteLine("Ops... wrong password");
}
You can generate a password like "WH4\"!0-I):". Then you can save the hash you your database or xml file, without any problem in keeping the hash in plain text. The user has the password and in runtime, you verify it like the example above.
The class
public string[] Generate( int n,
bool bIncludeLowerCase,
bool bIncludeNumbers,
bool bIncludeNonAlphaChars,
int iNumberOfFirstNonSymbolChars,
bool HashWanted)
is very (ok, blame me later...) well commented so I think it is easy to understand the global of it.The project has the class and in the main function you can see it working. It generates 32 new passwords with the hashes and in the end, the user inputs the password that will be checked.Any questions and bugs please report me.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.