Random password
Generates a random password by using given characters.
function random_password($length, $characters='abcdefgh1234567890'){
if ($characters == ''){ return ''; }
$chars_length = strlen($characters)-1;
mt_srand((double)microtime()*1000000);
$pwd = '';
while(strlen($pwd) < $length){
$rand_char = mt_rand(0, $chars_length);
$pwd .= $characters[$rand_char];
}
return $pwd;
}
//Example
random_password(5,'abcd1234') => returns something like: '2b4d3'
Url: http://www.jonasjohn.de/snippets/php/random-password.htm
Language: PHP | User: ShareMySnippets | Created: Oct 16, 2013