Click here to Skip to main content
13,202,155 members (55,136 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


11 bookmarked
Posted 8 Jun 2008

Simple Password Generator

, 8 Jun 2008
Rate this:
Please Sign up or sign in to vote.
Dynamic generation of password


Generating password is not a big deal. Pool the character from the character array and you will be generating password easily. This example shows how easily you can dynamically generate a password.Background

Using the code

PWDGenerator.cs uses System.Collections namespace to apply ArrayList. You can set the length of the password by setting the passwordlength to the length as you need.

This example simply demonstrate the basic use of Arraylist and Random number to generate random combinations or alphabets and numbers.

public static string GeneratePWD()


int passwordLength = 10;

int quantity = 1;

ArrayList arrCharPool = new ArrayList();

Random rndNum = new Random();


string password = "";

//Lower Case

for (int i = 97; i < 123; i++)





for (int i = 48; i < 58; i++)




//Upper Case

for (int i = 65; i < 91; i++)




for (int x = 0; x < quantity; x++)


//Iterate through the number of characters required in the password

for (int i = 0; i < passwordLength; i++)


password += arrCharPool[rndNum.Next(arrCharPool.Count)].ToString();



return password;


Build the application and start clicking the generate button. Instantly you will notice the changes. Here what I have done is selecting the integer values and converting them in the character which I have added to ArrayList and finally iterated through the generated characters from the ArrayList and generated a string of the specified length.

This example is simple and definitely you are going to enjoy by using it in your application.


  • Initial release - 9th June 2008.


From this article we can simply generate an algorithm to generate random strings in the format as we have designed. Suppose you want to generate a password in more redable form for the new users signed up in your application or website and you need to send them password, then in that case you can simply use the ramdom strings generated from the above application as a password to the new users.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer SAPNEP IT SOLUTION
Nepal Nepal
Working as a .Net programmer for SapNep IT Solution.


You may also be interested in...

Comments and Discussions

QuestionWhat? Pin
PIEBALDconsult8-Jun-08 18:52
memberPIEBALDconsult8-Jun-08 18:52 
AnswerRe: What? Pin
Vasudevan Deepak Kumar8-Jun-08 19:58
memberVasudevan Deepak Kumar8-Jun-08 19:58 
GeneralRe: What? Pin
lalum9-Jun-08 22:16
memberlalum9-Jun-08 22:16 
GeneralTo make it more comprehensive... Pin
Vasudevan Deepak Kumar8-Jun-08 18:44
memberVasudevan Deepak Kumar8-Jun-08 18:44 

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
Web01 | 2.8.171020.1 | Last Updated 8 Jun 2008
Article Copyright 2008 by RajuMaharjan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid