Click here to Skip to main content
13,096,858 members (83,065 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 13 Dec 2005

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


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.");




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


About the Author

Adelino Araújo
Portugal Portugal
No Biography provided

You may also be interested in...

Comments and Discussions

Questiongood job Pin
Gun Gun Febrianza18-Aug-12 8:28
memberGun Gun Febrianza18-Aug-12 8:28 
GeneralMy vote of 5 Pin
Gun Gun Febrianza18-Aug-12 8:28
memberGun Gun Febrianza18-Aug-12 8:28 
GeneralA GUI for the class Pin
P.Sandgren24-Oct-06 1:09
memberP.Sandgren24-Oct-06 1:09 
GeneralA small miss Pin
Pär Sandgren24-Oct-06 0:06
memberPär Sandgren24-Oct-06 0:06 
GeneralWould need more feature Pin
Arch4ngel14-Dec-05 9:19
memberArch4ngel14-Dec-05 9:19 
AnswerRe: Would need more feature Pin
Adelino Araújo14-Dec-05 11:15
memberAdelino Araújo14-Dec-05 11:15 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170813.1 | Last Updated 13 Dec 2005
Article Copyright 2005 by Adelino Araújo
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid