Generating Random Passwords

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

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 181 articles.

You can find more information from dwirch by visiting

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.

Recent Forum Posts

Advanced search added
dwirch posted on September 23, 2017 at about 13:44 in Site News

Job Spammer: Gaurav Mehta - AgreeYa Solutions
dwirch posted on September 22, 2017 at about 10:35 in Spammers

Job Spammer: Prutha Siri - Javelin Systems
dwirch posted on September 10, 2017 at about 6:15 in Spammers

New security implemented
dwirch posted on September 7, 2017 at about 7:16 in Site News

Malicious IP Checker Companion Tool
dwirch posted on August 12, 2017 at about 20:24 in Site News

Job Spammer: Steve Adams
dwirch posted on August 8, 2017 at about 7:44 in Spammers