Generating Random Passwords

Posted On 2013-09-23 by dwirch
Keywords: VB6 PHP
Tags: Scripting Webmaster Related ASP Windows Linux
Views: 482

Once again, someone has decided to sell some knowledge.  Nothing burns me up more than someone trying to make a quick buck off something so simple as generating a random password.

You should know this

Generating passwords is something that any competent programmer should be able to do in about 5 minutes.  Even if you don't know any code, you (as a developer) should be able to at least flowchart or psuedo-code something like this. So to help those of you who don't know how to do this, I've pasted the code below, in both PHP and ASP.  Any questions, drop a note in the programming forum.


function generatePassword($length=9, $strength=0) {
	$vowels = 'aeuy';
	$consonants = 'bdghjmnpqrstvz';
	if ($strength & 1) {
		$consonants .= 'BDGHJLMNPQRSTVWXZ';
	if ($strength & 2) {
		$vowels .= "AEUY";
	if ($strength & 4) {
		$consonants .= '23456789';
	if ($strength & 8) {
		$consonants .= '@#$%';
	$password = '';
	$alt = time() % 2;
	for ($i = 0; $i < $length; $i++) {
		if ($alt == 1) {
			$password .= $consonants[(rand() % strlen($consonants))];
			$alt = 0;
		} else {
			$password .= $vowels[(rand() % strlen($vowels))];
			$alt = 1;
	return $password;



response.write PasswordGenerator(9,0) 

Function PasswordGenerator(intLength,IntStrength) 

Randomize Timer 


Select Case intStrength 

	Case 1 
	Case 2 
	Case 4 
	Case 8 
End Select 

for intKount=0 to intLength 

	if intBW < 50 then 
		strPassword=strPassword & mid(strConsonants,int(rnd(1)*len(strConsonants)+1),1) 
		strPassword=strPassword & mid(strVowels,int(rnd(1)*len(strVowels)+1),1) 
	end if 


End Function 


There you go. Keep your hard earned money.

About the Author

dwirch has posted a total of 172 articles.


Comments On This Post

No comments on this post yet!

Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.

Your IP address is:

Before you can post, you need to prove you are human. If you log in, this test goes away.

Beat With A Stick List Returns: By request, BWASL has returned to the site. Free your rage by telling the world about something that really grinds your gears. Add your beating.

Recent Forum Posts

BWASL returns
dwirch posted on May 13, 2017 at about 15:24 in Site News

BWASL returns
dwirch posted on May 13, 2017 at about 8:46 in Site News

Job Spammer: Balashankar Bose Bose
dwirch posted on May 11, 2017 at about 10:05 in Spammers

Job Spammer: Bharti Jigyasi
dwirch posted on May 11, 2017 at about 7:58 in Spammers

List of Shady Characters
dwirch posted on April 25, 2017 at about 16:39 in Webmaster Stuff

Job Spammer: Bilal Uddin
dwirch posted on April 25, 2017 at about 11:00 in Spammers