What it does: Generates a random password using a chosen character set. The live demo lets you pick length to see how the output changes.
Tip: For real apps, prefer longer lengths and avoid storing passwords—store salted hashes instead.
Generate a secure random password.
<?php
$len = isset($_GET['len']) ? max(4, min(64, (int)$_GET['len'])) : 10;
function rand_password($length){
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#%&*()_?;:=+';
$s=''; $m=strlen($chars)-1;
for($i=0;$i<$length;$i++) $s.=$chars[random_int(0,$m)];
return $s;
}
echo rand_password($len);
?>