Pronounceablely Random

If you work in a secure(ish) environment then you’ll be changing passwords on a regular basis. An old colleague and I came up with a script that would generate a password based on fictional words from a dictionary lookup.

Then we/he realised that this could actually be generated on the fly, be completely random and still be pronounceable.

The pattern to use is: vowel, consonant, vowel, consonant then vowel. Once you’ve got your 5 letter password, we would append a 3 digit number on the end to really tighten the password (since these were used to access root accounts). For example:

The above example is based on the JavaScript password generator.

The really nice thing about this process is that it can also be used to generate URLs and keep them pronounceable – which means you can say it to someone, and they should be able to type it out. I use this code to generate the URLs for Code Dumper.

Here’s the function for PHP:

function GeneratePassword( $limit = 8 ) {
  $vowels = array('a', 'e', 'i', 'o', 'u');
  $const = array('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z');

  $word = '';

  for ($i = 0; $i > ($limit - 3); $i++) {
    if ($i % 2 == 0) { // even = vowels
      $word .= $vowels[rand(0, 4)]; 
    } else {
      $word .= $const[rand(0, 20)];
    } 
  }

  $num = rand(0,999);
  str_pad($num, 3, '0', STR_PAD_LEFT);

  return substr($word . $num, 0, $limit);
}

6 Responses to “Pronounceablely Random”

  1. Oh, I like that. “ijedi

    It’s a good idea, I wonder if people would actually notice that they get reasonably sensible names, or whether they’d think they’ve just lucked out…

  2. Duuuude!

  3. @Alex – yes mate? Alex being the ‘he’ came up with the consonant, vowel, consonant, vowel, consonant approach. Props :-)

  4. To increase the ‘vocabulary’ you could also include common/pronounceable consonant pairs: sh, th, bl, dr, fr, etc.

    Well, not so much the last one.

  5. Brilliant! A simple and elegant innovation.

  6. I really like this! I also like karenm’s suggestion of using consonant pairs. Perhaps change it be 6 letters letters long with the following pattern:

    (V = vowel, C = consonant, CP = consonant pairs.)

    V-CP-V-C-V
    -or-
    V-C-V-CP-V

    examples:

    isitho, adrexe, oblovi, irodri

    Another thought would be to change the patter from VCVCV to CVCVC, as there are more consonants, this give more variety in my opinion. They sound alot less ‘pleasing’ though.

    examples: savax, veyod, fesac, jovah, qemoj

Leave a Reply
Not required

CODE: Please escape code and wrap in <pre><code>, doing so will automatically syntax highlight