Created
September 1, 2022 15:29
-
-
Save guimadaleno/8ec01944ee552dcd6d993316ad4cae5d to your computer and use it in GitHub Desktop.
Generate random password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Generate a random password | |
* @param int $length | |
*/ | |
function random_password ($length = 8, $chars = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789") | |
{ | |
$pw = []; | |
$l = strlen($chars) - 1; | |
for ($i = 0; $i < $length; $i++): | |
$n = rand(0, $l); | |
$pw[] = $chars[$n]; | |
endfor; | |
return implode($pw); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment