#native_company# #native_desc#
#native_cta#

Pronounceable Password Generator

By Sebastien Cevey
on January 2, 2001

Version: 1.0

Type: Function

Category: Algorithms

License: GNU General Public License

Description: Create a random pronounceable password, with random case.
Can be easily customized.

<?php 

/* *
 *  Function : string rand_pass()
 *
 *  Purpose : Returns a random but pronounceable password.
 *  Note: You may edit the $num_letters and $array variables
 *
 *  Author: Sebastien Cevey <[email protected]>
 *  Project: Web OpenScripts <http://wos.sourceforge.net>
 * */

function rand_pass() {

  # Pronounceable pieces of words
  $array = array(
		 "ap","dus","tin","rog","sti","rev","pik","sty","lev","qot","rel","vid",
		 "kro","xo","pro","wia","axi","jer","foh","mu","ya","zol","gu","pli","cra",
		 "den","bi","sat","ry","qui","wip","fla","gro","tav","peh","gil","lot",
		 "kal","zan","noc","bat","tev","lun","pal","hom","cun","wos","vox"
		 );

  # The number of letters
  $num_letters = 6;

  # Fraction of uppercased letters (randomized too...)
  $uppercased = 3;

  # Randomize on microseconds
  mt_srand ((double)microtime()*1000000);

  # Create random pass (too long for the moment)
  for($i=0; $i<$num_letters; $i++)
    $pass .= $array[mt_rand(0, (count($array) - 1))];

  # Make sure there is not twice the same letter one after the other
  for($i=1; $i<strlen($pass); $i++) {
    if(substr($pass, $i, 1) == substr($pass, $i-1, 1))
      $pass = substr($pass, 0, $i) . substr($pass, $i+1);
  }

  # Randomize the pass case [for each letter]
  for($i=0; $i<strlen($pass); $i++) {
    if(mt_rand(0, $uppercased) == 0)
      $pass = substr($pass,0,$i) . strtoupper(substr($pass, $i,1)) . substr($pass, $i+1);
  }

  # Shorten it now
  $pass = substr($pass, 0, $num_letters);

  # Return the password
  return $pass;
}

echo rand_pass();

?>