- 29 Tem 2017
- 3,476
- 990
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:
Hide Copy Code
The class
Kod
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 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:
Hide Copy Code
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.// build a new passwordgenerator object
// and call the Generate method with the parameters
PasswordGenerator p = new PasswordGenerator();
string[] pass = p.Generate(8, true, true, true, 2,true);
// we're accessing pass[1] because we wanted the hash
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.
Hide Copy Code
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");
}
The class
Kod
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.
Moderatör tarafında düzenlendi: