<?php
function generate_pass($length) {
$charsstring = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789';
$countchars = mb_strlen($charsstring);
for ($i=0, $result=''; $i<$length; $i++) {
$index = rand(0, $countchars-1);
$pass = $pass . mb_substr($charsstring, $index, 1);
}
return $pass;
}
// Here we call the function, and get the new password back
$MyPass = generate_pass(6);
// Here we print the new password to the browser
echo "Hey! You have a password..";
echo $MyPass;
?>
Jeg har fjernet I, l, L, i, o, O, 0, 1 fra listen af numre og tegn fra alfabetet, for at undgå fejltagelser.
Prøv at ændre værdien fra 6 til andre værdier, for længden af password.