created: 2005-05-19
modified: 2005-06-23

Stefan.Huberdoc.at

Randompassword: a random password generator

I once used a useful small piece of code written by Chris Hunt in May 2005. The original implementation can be found at http://www.extraconnections.co.uk/web/password.shtml. I made some minor modifications.

randompassword is a small PHP function that can easily be transcribed into other languages. I am using it in Delphi as well. Its purpose is to generate pronouncable and thus memorable passwords. Sometimes, numbers or punctutaion are inserted. There's always a way to pronounce numbers as letters (4 as A, 8 as B, whatever).

Of course, the password is not 100% random, since there's an algorithm in the background creating it. But it should provide enough protection against evil colleagues or hobby hackers. The greatest benefit is that they are easy to remember, because most if not all of them can be pronounced. So no need for post-its attached to the monitor :)

Example

The source code of the function is below the example. Now, this is an the output of a PHP script using the function:

It seems, your browser thinks I am a security risk. You have to follow the link to randompassword.php manually.

Source code

This is the source code I am using for the password generator. Important notice: You can use it as you like, as long as you keep on giving credit to Chris Hunt as the original author and point at least to this very web page and Chris Hunt's for reference. As usual, I don't take responsability for any problems that may arise by using the function or passwords generated with it.

function randompassword(
  $desiredlen = 8,
  $capitalprob = 10,
  $mutationprob = 15
  ) {
$vowels = array(
           "a" , "a" , "a" , "e" , "e" , "e" , "i" , "i" ,
           "o" , "o" , "u" , "u" , "ae", "ai", "au", "ao",
           "ay", "ea", "ei", "ey", "ua", "ia", "ie", "io",
           "oa", "oe", "ou", "oy", "!" , "1" , "4", "3"
           );
$cons = array(
         "b" , "c" , "d" , "f" , "g" , "h" , "j" , "k" ,
         "l" , "m",  "n" , "p" , "q" , "r" , "s" , "t" ,
         "v" , "w" , "x" , "z" , "cs", "ck", "ch", "cz",
         "7" , "2" , "5" , "6" , "8" , "9"
        );

  $passwd = "";
  $vowelnext   = rand(0,1);

  do {
    if ($vowelnext) {
      $nextpart = $vowels[array_rand($vowels)];
    } else {
      $nextpart = $cons[array_rand($cons)];
    }
    if (rand(0,100) < $capitalprob) {
      $nextpart = strtoupper($nextpart);
    }
    $passwd .= $nextpart;
    if (rand(0,100) > $mutationprob) {
      $vowelnext = !$vowelnext;
    }
  } while (strlen($passwd) < $desiredlen);
  return $passwd;
}

Credits for the original idea go definitely to Chris Hunt.

Contact & ImprintKontakt & Impressum
Created: 2005-05-19 — last modified: 2005-06-23 — last update of web site: 2012-01-25
Follow me: RSS Follow StefanMHuber on Twitter