Skip to content

Instantly share code, notes, and snippets.

@antic183
Created February 21, 2018 08:08
Show Gist options
  • Save antic183/83d8f51d337dab003fe0768b47c4405f to your computer and use it in GitHub Desktop.
Save antic183/83d8f51d337dab003fe0768b47c4405f to your computer and use it in GitHub Desktop.
php random password generator
<?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