Last weekend, I passed very boring time in my home. Didn’t have that much work load. I am thinking to do something fun. And then I wrote a open source PHP class that generates Random password. Well, later on I used it in one of my clients’ project. Some of my friends also start using this class. So, I feel that I need to share with everyone. . 🙂
Source codes is available here: http://github.com/eftakhairul/Random-Password-Generator
Let me show some examples:
$testPass = new RandomPassword(); echo $testPass->useNumbers(3)->generatePassword(9);
Output:
QACror747
Again:
$testPass->useNumbers(2)->useSpecialChars(3); echo $testPass->generatePassword(10);
Output:
OXAus#@^01
Hmm class seems abit over the top, also listing all the chars is abit silly. i just wrote this, much easier
[code]
for ($i = 0; $i <= $length; ++$i) {
$password .= chr(rand(47, 126));
}
[/code]
Thanks for your comments. Actually, there are multiple ways to do it. I just did in my own way ..
The problem with this is it does not guarantee any degree of complexity; it’s entirely possible for this snippet to still generate a password like “adahdaha” (only three unique characters, all lowercase) even though the valid character range includes uppercase, lowercase, numbers, and symbols.
Thanks Doktor for your comments. I am checking the script. If there anything wrong . I will check.
Useful info, guys. Thanks!
Thanks for your comment.