1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
<?php
function generate_passwd($nb=8)
{
$lettre = array();
$lettre[0] = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'o', 'n', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A',
'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'D',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '9',
'0', '6', '5', '1', '3');
$lettre[1] = array('a', 'e', 'i', 'o', 'u', 'y', 'A', 'E',
'I', 'O', 'U', 'Y' , '1', '3', '0' );
$lettre[-1] = array('b', 'c', 'd', 'f', 'g', 'h', 'j', 'k',
'l', 'm', 'n', 'p', 'q', 'r', 's', 't',
'v', 'w', 'x', 'z', 'B', 'C', 'D', 'F',
'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P',
'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Z',
'5', '6', '9');
$retour = '';
$prec = 1;
$precprec = -1;
srand((double)microtime() * 20001107);
while(strlen($retour) < $nb)
{
// To generate the password string we follow these rules : (1) If two
// letters are consonnance (vowel), the following one have to be a vowel
// (consonnace) - (2) If letters are from different type, we choose a
// letter from the alphabet.
$type = ($precprec + $prec) / 2;
$r = $lettre[$type][array_rand($lettre[$type], 1)];
$retour .= $r;
$precprec = $prec;
$prec = in_array($r, $lettre[-1]) - in_array($r, $lettre[1]);
}
return $retour;
}
echo generate_passwd();
?> |
Partager