Skip to content

Instantly share code, notes, and snippets.

@sourleangchhean168
Created May 2, 2022 07:23
Show Gist options
  • Save sourleangchhean168/aaa08cf0b8224336f8df4021c6754cdd to your computer and use it in GitHub Desktop.
Save sourleangchhean168/aaa08cf0b8224336f8df4021c6754cdd to your computer and use it in GitHub Desktop.
Password Random Generator in PHP
<?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