PHP: Create a human readable password

Create a human readable password string like “wokubuti” or “faxikali”.
Though a password sometimes need to be stronger, it’s useful for many purpurses like auto generated names. Just pass a length to this PHP function, and it will return a readable string.

function randomPassword($len = 8)
{
   if(($len%2) !== 0){ // Length paramenter must be a multiple of 2
      $len = 8;
   }
   $length = $len; //$length = $len - 2; // Makes room for the two-digit number on the end
   $conso = array('b','c','d','f','g','h','j','k','l','m','n','p','r','s','t','v','w','x','y','z');
   $vocal = array('a','e','i','o','u');
   $password = '';
   srand((double)microtime() * 1000000);
   $max = $length / 2;
   for($i=1; $i<=$max; $i++){
      $password .= $conso[rand(0,19)];
      $password .= $vocal[rand(0,4)];
   }
   $newpass = $password;
            
   return $newpass;
}

Leave a Reply

Your email address will not be published. Required fields are marked *