Skip to content

Instantly share code, notes, and snippets.

@joseporiol
Created February 25, 2014 13:38
Show Gist options
  • Save joseporiol/9208854 to your computer and use it in GitHub Desktop.
Save joseporiol/9208854 to your computer and use it in GitHub Desktop.
Random password of 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment