Click here to Skip to main content
Click here to Skip to main content
Go to top

Password Generator

, 13 Dec 2005
Rate this:
Please Sign up or sign in to vote.
This program generates random passwords (and SHA1 hash)

Sample Image - PasswordGenerator.jpg

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:

// 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.

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Adelino Araújo

Portugal Portugal
No Biography provided

Comments and Discussions

 
Questiongood job PinmemberGun Gun Febrianza18-Aug-12 8:28 
GeneralMy vote of 5 PinmemberGun Gun Febrianza18-Aug-12 8:28 
GeneralA GUI for the class PinmemberP.Sandgren24-Oct-06 1:09 
GeneralA small miss PinmemberPär Sandgren24-Oct-06 0:06 
GeneralWould need more feature PinmemberArch4ngel14-Dec-05 9:19 
AnswerRe: Would need more feature PinmemberAdelino Araújo14-Dec-05 11:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 13 Dec 2005
Article Copyright 2005 by Adelino Araújo
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid