Simple library for generating random passwords.
- PHP >= 5.3.2
Add HackzillaPasswordGenerator in your composer.json:
{
"require": {
"hackzilla/password-generator": "~1.0"
}
}
Install Composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
Now tell composer to download the library by running the command:
$ composer update hackzilla/password-generator
Composer will install the bundle into your project's vendor/hackzilla
directory.
use Hackzilla\PasswordGenerator\Generator\ComputerPasswordGenerator;
$generator = new ComputerPasswordGenerator();
$generator
->setOptionValue(ComputerPasswordGenerator::OPTION_UPPER_CASE, true)
->setOptionValue(ComputerPasswordGenerator::OPTION_LOWER_CASE, true)
->setOptionValue(ComputerPasswordGenerator::OPTION_NUMBERS, true)
->setOptionValue(ComputerPasswordGenerator::OPTION_SYMBOLS, false)
;
$password = $generator->generatePassword();
If you want to generate 10 passwords that are 12 characters long.
use Hackzilla\PasswordGenerator\Generator\ComputerPasswordGenerator;
$generator = new ComputerPasswordGenerator();
$generator
->setUppercase()
->setLowercase()
->setNumbers()
->setSymbols(false)
->setLength(12);
$password = $generator->generatePasswords(10);
use Hackzilla\PasswordGenerator\Generator\HybridPasswordGenerator;
$generator = new HybridPasswordGenerator();
$generator
->setUppercase()
->setLowercase()
->setNumbers()
->setSymbols(false)
->setSegmentLength(3)
->setSegmentCount(4)
->setSegmentSeparator('-');
$password = $generator->generatePasswords(10);
If you can think of a better name for this password generator then let me know.
The segment separator will be remove from the possible characters.
use Hackzilla\PasswordGenerator\Generator\HumanPasswordGenerator;
$generator = new HumanPasswordGenerator();
$generator
->setWordList('/usr/share/dict/words')
->setWordCount(3)
->setWordSeparator('-');
$password = $generator->generatePasswords(10);
- Password Generator Library [https://github.com/hackzilla/password-generator-app]
- Password Generator Bundle [https://github.com/hackzilla/password-generator-bundle]
This library uses mt_rand which is does not generate cryptographically secure values. Basically an attacker could predict the random passwords this library produces given the right conditions.
If you have a source of randomness you can inject it into the PasswordGenerator, using RandomGeneratorInterface.
PHP 7 has random_int function which they say is good to use for cryptographic random integers.
use Hackzilla\PasswordGenerator\Generator\HumanPasswordGenerator;
use Hackzilla\PasswordGenerator\RandomGenerator\Php7RandomGenerator;
$generator = new HumanPasswordGenerator();
$generator
->setRandomGenerator(new Php7RandomGenerator())
->setWordList('/usr/share/dict/words')
->setWordCount(3)
->setWordSeparator('-');
$password = $generator->generatePasswords(10);