Last active
February 12, 2022 15:56
-
-
Save nagiyevelchin/ad477f6300e9c3e849d642f07016eb52 to your computer and use it in GitHub Desktop.
Generate complex random password in PHP
This file contains hidden or 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 random password | |
* @param int $length [optional] [default 9] length password to be generated | |
* @return string | |
* @link http://www.webtoolkit.info/php-random-password-generator.html | |
* @since 12/1/12 11:30 AM | |
*/ | |
function generatePassword($length = 9) { | |
$vowels = 'aeuy'; | |
$consonants = 'bdghjmnpqrstvz'; | |
$consonants .= 'BDGHJLMNPQRSTVWXZ'; | |
$vowels .= "AEUY"; | |
$consonants .= '23456789'; | |
$consonants .= '@#$%'; | |
$password = ''; | |
$alt = time() % 2; | |
for ($i = 0; $i < $length; $i++) { | |
if ($alt == 1) { | |
$password .= $consonants[(rand() % strlen($consonants))]; | |
$alt = 0; | |
} else { | |
$password .= $vowels[(rand() % strlen($vowels))]; | |
$alt = 1; | |
} | |
} | |
return $password; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment