Generating Random Passwords

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

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.

Recent Forum Posts

Job Spammer: Sathya Narayana
dwirch posted on March 15, 2017 at about 7:18 in Spammers

Job Spammer: Manish Kumar
dwirch posted on March 14, 2017 at about 17:44 in Spammers

Site Migration Complete
dwirch posted on March 12, 2017 at about 11:10 in Site News

Site Migration Complete
dwirch posted on March 11, 2017 at about 0:35 in Site News

Job Spammer: Jason Weinstein
dwirch posted on March 10, 2017 at about 14:00 in Spammers

Job Spammer: Ryan Wilson
dwirch posted on March 8, 2017 at about 17:00 in Spammers