Simple function to generate the password, given a length.
/* Defining the function */
function pwgen ($len) {
/* Variables declaration */
$pw = "";
$wordBook = array ();
/* Fill array with printable english characters */
for ( $wb=33; $wb<127; $wb++ ) {
array_push ( $wordBook, $wb );
}
shuffle ( $wordBook ); // Shake
$pass = array_rand ( $wordBook , $len ); // Slice a part
shuffle ( $pass ); // Shake again
/* Save the array into variable */
foreach ( $pass as $i => $wb_index ) {
$pw .= chr ( $wordBook [$wb_index] );
}
return $pw;
}
/* Calling the function and passing 10 as length */
print pwgen(10);code type:
