<?php

/*****************************************************************************
 * Password generator 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA,
 * or go to http://www.gnu.org/copyleft/gpl.html

Original: Crée un mot de passe prononcable en anglais.
Auteur : Sterling Hughes
Url : http://bumblebury.com/
http://www.nexen.net/scripts/details.php?scripts=718

Hacked by Robert Sebille - robert.sebille[AT]banlieues[DOT]be 2005
Company: Banlieues asbl, 412c chaussée de Waterloo, 1050 Bruxelles - Belgique
- To be sure to avoid XSS, min = 5, max = 50
- To french pronounciation
- Added random number(s)
- Added random uppercase 
- Added level 0, 1, 2, 3
Level 0: 1 time 1 random number 10 > 99, followed of lowercase syllables -> length
Level 1: (1 lowercase syllable, followed of 1 random number 10 > 99) X time -> length
Level 2: (1 lowercase OR UPPERCASE syllable, followed of 1 random number 10 > 99) X time -> length
Level 3: (1 lowercase/UPPERCASE mixed syllable, followed of 1 random number function of length) X time -> length
-  function ana_pass($anapass) 
***********************************************/

  
function gen_pass($lengthBrut=8$levelBrut=0){
     
// To be sure to avoid XSS
      
$length intval($lengthBrut); $level intval($levelBrut);
     
// min = 5, max = 50
     
if ($length 5) {$length 5;}
     if (
$length 50) {$length 50;}
     
// A List of vowels and vowel sounds that we can insert in
        // the password string level =1 or 2
        
$vowels = array("a""e""i""o""u""y""ai""au""ay""eu""in""oi""on""ou""oy"); 
        
// A List of Consonants and Consonant sounds that we can insert
        // into the password string
        
$consonants = array("b""c""d""g""h""j""k""l""m""n""p""qu""r""s""t""v""z""bl""br""ch""cl""cr""dr""fr""gl""gn""gr""gu""ph""pl""pr""st""tr");
             
     
// For the call to rand(), saves a call to the count() function
     // on each iteration of the for loop
     
$vowel_count count($vowels); 
     
$consonant_count count($consonants); 
    
     
// From $i .. $length, fill the string with alternating consonant
     // vowel pairs.
     
$pass "";
     switch (
$level) {

             case 
0:
                
$pass .= rand(10,99);
                for (
$i 0$i $length; ++$i) {
                     
$pass .= $consonants[rand(0,  $consonant_count 1)];
                    
$pass .= $vowels[rand(0,  $vowel_count 1)];
                 } 
// for ($i = 0; $i < $length; ++$i)         
                 
break;

             case 
1:
                for (
$i 0$i $length; ++$i) {
                     
$pass .= $consonants[rand(0,  $consonant_count 1)];
                    
$pass .= $vowels[rand(0,  $vowel_count 1)];
                    
$pass .= rand(10,99);
                 } 
// for ($i = 0; $i < $length; ++$i)         
                 
break;

             case 
2:
                for (
$i 0$i $length; ++$i) {
                     if (
rand(0,1) == 1) {
                         
$pass .= strtoupper($consonants[rand(0,  $consonant_count 1)]);
                         
$pass .= strtoupper($vowels[rand(0,  $vowel_count 1)]);
                         }
                     else {
                         
$pass .= $consonants[rand(0,  $consonant_count 1)];
                        
$pass .= $vowels[rand(0,  $vowel_count 1)];
                        } 
// if (rand(0,1) == 1)
                    
$pass .= rand(10,99);
                 } 
// for ($i = 0; $i < $length; ++$i)             
                 
break;

             case 
3:
                 for (
$i 0$i $length; ++$i) {
                     if (
rand(0,1) == 1) {$pass .= strtoupper($consonants[rand(0,  $consonant_count 1)]);}
                         else {
$pass .= $consonants[rand(0,  $consonant_count 1)];}
                 if (
rand(0,1) == 1) {$pass .= strtoupper($vowels[rand(0,  $vowel_count 1)]);}
                         else {
$pass .= $vowels[rand(0,  $vowel_count 1)];}
                    
$pass .= rand(1,100*($i+1));
                 } 
//for ($i = 0; $i < $length; ++$i)             
                 
break;

             default: 
$pass "Non authorized level. Level = 0, 1, 2 or 3";
             } 
// switch ($level)
                
     // Since some of our consonants and vowels are more than one
     // character, our string can be longer than $length, use substr()
     // to truncate the string
     
if ($level >= AND $level <= 3) {$pass substr($pass,  0,  $length);}
     
     return 
$pass;
 
}

  function 
ana_pass($anapass){
  
         
$pass_lettres str_replace ("l"" [lettre l] "$anapass);
         
$pass_lettres str_replace ("O"" [lettre O] "$pass_lettres);
         
$pass_lettres str_replace ("o"" [lettre o] "$pass_lettres);
         
$pass_lettres str_replace ("I"" [lettre I] "$pass_lettres);
         
$pass_lettres_chiffres str_replace ("0"" [chiffre 0] "$pass_lettres);
         
$pass_lettres_chiffres str_replace ("1"" [chiffre 1] "$pass_lettres_chiffres);

        return 
$pass_lettres_chiffres;
    
 }
 
 
?>