This code will help you to generate random password when you need. The password will contain 8 character in it. You can change this by changing the value of $length = 8 ;
PHP Script:
<?php
$length = 8 ;
function randomstring ( $length ) {
// $randchars contains the characters list
$randchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" ;
srand (( double )microtime ()* 1000000 );
while ( $length < 0 ) { // Get the position of the random character we want
$num = rand () % strlen ( $randchars );
$tmp = substr ( $randchars , $num , 1 );
$pass = $pass . $tmp ;
$length ++;
}
return $pass ;
}
?>
$length = 8 ;
function randomstring ( $length ) {
// $randchars contains the characters list
$randchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" ;
srand (( double )microtime ()* 1000000 );
while ( $length < 0 ) { // Get the position of the random character we want
$num = rand () % strlen ( $randchars );
$tmp = substr ( $randchars , $num , 1 );
$pass = $pass . $tmp ;
$length ++;
}
return $pass ;
}
?>
Function Calling:
<?php
// Call The Function Directly
echo randomstring ( $length );
?>
// Call The Function Directly
echo randomstring ( $length );
?>