php class for random and secure password generation
composer require tbetool/php-password-generator
use TBETool\PasswordGenerator;
$passwordGenerator = new PasswordGenerator();
You can optionally pass following parameters to constructor
use TBETool\PasswordGenerator;
$passwordGenerator = new PasswordGenerator($length, $count, $characters);
$length (int) : Length of the password to generate, Default: 8
$count (int) : No of passwords to generate, Default: 1
$characters (string): Characters to use while password generation
- lower_case
- upper_case
- numbers
- special_symbols
use TBETool\PasswordGenerator;
$passwordGenerator = new PasswordGenerator(16, 5, 'lower_case,numbers,special_symbols');
Parameters set during object creation will be overwritten.
# Set lenght of password to 16
# params: (int) length
$passwordGenerator->setLength(16);
# Set number of passwords to generate
# params: (int) count
$passwordGenerator->setCount(5);
# Set characters to use in password
# params: (string) characters
$passwordGenerator->setCharacters('lower_case,numbers');
This will return single password from all passwords generated
@return string of password
$password = $passwordGenerator->generate();
@return array of passwords
$passwords = $passwordGenerator->getPasswords();
@return string of new password
$password = $passwordGenerator->getPassword();
@return string of last password retrieved
$password = $passwordGenerator->getLastPassword();
Anuj Sharma (https://anujsh.in)