Bonjour,
J'aimerais un script qui génère un mot de passe aléatoire de 8 caractères avec 6 minuscules, 1 majuscule et 1 chiffre.
Je n'ai rien trouvé sur les autres forums, quelqu'un peut m'aider ?
Merci
ev@d
Code : Tout sélectionner
<?php
function generate_password($size) {
$listeChar = '23456789abcdefghkpqrstwxyzABCDEFGHKJLMNPQRSTUVWXYZ';
$max = strlen($listeChar)-1;
$key = '';
for ($i=0;$i<$size;$i++) {
$key .= $listeChar[mt_rand(0,$max)];
}
return $key;
}
echo generate_password(8);
?>
$listeNb = '23456789';
$listeMin = 'abcdefghkpqrstwxyz';
$listeMaj = 'ABCDEFGHKJLMNPQRSTUVWXYZ';
$tab = array();
$tab[] = $listeNb[mt_rand(0, strlen($listeNb)-1)]; // 1 chiffre
$tab[] = $listeMaj[mt_rand(0, strlen($listeMaj)-1)]; // 1 majuscule
for ($i=0;$i<6;$i++) { // 6 minuscules
$tab[] = $listeMin[mt_rand(0, strlen($listeMin)-1)];
}
shuffle($tab); // mélange les lettres
return implode('', $tab);