Generate random passwords length prefixed, with PHP
The PHP code described below, allows you to generate random passwords of fixed length.
Code:
<?php
function random_chars( $phrase ) {
$len = strlen( $phrase );
$pos = mt_rand( 0, $len-1 );
return ($phrase[$pos]);
}
function random_string( $charset, $len ) {
$password = "";
for($i=0; $i<$len; $i++) {
$password.= random_chars( $charset );
}
return $password;
}
$set = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcbefghijklmnopqrstuvwxyz0123456789[]+#&£$";
$p = random_string( $set, 12 );
echo("Your password is: $p");
?>
Result of this example:
Your password is: $O18kbM5MkoF