Search Tools Links Login

Generating Random Passwords


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.

PHP

<!--?php
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;
}

?-->

ASP

<%
response.write PasswordGenerator(9,0)

Function PasswordGenerator(intLength,IntStrength)

Randomize Timer

strPassword=""
strVowels="aeuy"
strConsonants="bdghjmnpqrstvz"

Select Case intStrength

     Case 1
          strConsonants="BDGHJLMNPQRSTVWXZ"

     Case 2
          strVowels="AEUY"

     Case 4
          strConsonants="23456789"

     Case 8
          strConsonants="@#$%"

End Select

for intKount=0 to intLength

     intBW=int(rnd(1)*100)+1

     if intBW < 50 then

          strPassword=strPassword & mid(strConsonants,int(rnd(1)*len(strConsonants)+1),1)
          intBW=0

     else

          strPassword=strPassword & mid(strVowels,int(rnd(1)*len(strVowels)+1),1)
          intBW=1

     end if

Next

PasswordGenerator=strPassword

End Function

%>

There you go. Keep your hard earned money.

About this post

Posted: 2013-09-23
By: dwirch
Viewed: 928 times

Categories

Webmaster Related

Scripting

ASP/ HTML

Linux

Windows

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.