Created
May 2, 2022 07:23
-
-
Save sourleangchhean168/aaa08cf0b8224336f8df4021c6754cdd to your computer and use it in GitHub Desktop.
Password Random Generator in PHP
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 | |
function randomPassword() { | |
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789"; | |
$pass = array(); | |
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache | |
for ($i = 0; $i < 8; $i++) { | |
$n = rand(0, $alphaLength); | |
$pass[] = $alphabet[$n]; | |
} | |
return implode($pass); //turn the array into a string | |
} | |
echo randomPassword(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment