Created
February 21, 2018 08:08
-
-
Save antic183/83d8f51d337dab003fe0768b47c4405f to your computer and use it in GitHub Desktop.
php random password generator
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 getRandomPassword($passwordLength = 4) { | |
$alphabet = 'abcdefghijklmnopqrstuvwxyz'; | |
$characterCollection = array_merge(str_split($alphabet), str_split(strtoupper($alphabet)), str_split('1234567890'), str_split('!~@#-_+<>[]{}')); | |
$randomPassword = ''; | |
for($i = 0; $i < $passwordLength; $i++) { | |
$randomPassword .= $characterCollection[array_rand($characterCollection)]; | |
} | |
return $randomPassword; | |
} | |
echo htmlspecialchars(getRandomPassword()) . '<hr/>'; | |
echo htmlspecialchars(getRandomPassword(7)) . '<hr/>'; | |
echo htmlspecialchars(getRandomPassword(100)) . '<hr/>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment