<html>
<body>
<code>
<?php
if ($_GET["source"]){
highlight_file(__FILE__);
return 0;
}
$passwordLength = 20;
$alphabet = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789~@#$%^&*(){}[]<>_-+=:;,./\|?";
$alphaLength = strlen($alphabet);
function symbol($x) {
global $alphabet, $alphaLength;
return $alphabet[$x % $alphaLength]; // slight bias for symbols on the left if 2^16 not a multiple of alphaLength
}
$handle = fopen("/dev/random", "rb") or die("Couldn't open /dev/random");
$bits = fread($handle, $passwordLength * 2);
fclose($handle);
$password = implode(array_map("symbol", unpack("S*", $bits)));
echo htmlspecialchars($password);
// e.g. DjE3]<IVzSxIuP[8
?>
</code>
<?php
printf("<br>Entropy: %.1f bits\n", log($alphaLength)/log(2)*$passwordLength);
printf("<br>alphaLength: %d symbols\n", $alphaLength);
echo "<br><a href=\"?source=1\" target=\"_blank\">Show the code</a>.";
?>
</body>
</html>