Generate a random string





11
Date Submitted Mon. Oct. 9th, 2006 4:57 AM
Revision 1 of 1
Helper serpentskiss
Tags Password | Random
Comments 1 comments
Creates a random string, usefull for passwords etc.

Use: $password = makeRandomPassword($Length);

If $Length is not specified (ie $password = makeRandomPassword();) then it will default to 8 characters

function makeRandomPassword($Len=8) {
   $salt = 'ABCDEFGHJKLMNPQRSTUXYZabchefghjkmnpqrstuvwxyz()%*^~#_<>;:&23456789';
   srand((double)microtime()*1000000);
      $i = 0;
      $Password = "";
      for ($i=0; $i < $Len; $i++){
         $num = rand() % strlen($salt);
         $Password .= substr($salt, $num, 1);
      }
      return $Password;
}
 

Jon Thompson

Comments

Comments I wanted to hate it
Mon. Oct. 9th, 2006 9:04 AM    Scripter sehrgut

Voting