Skip to content
php class for random and secure password generation
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


php class for random and secure password generation


composer require tbetool/php-password-generator


Create object

use TBETool\PasswordGenerator;

$passwordGenerator = new PasswordGenerator();

You can optionally pass following parameters to constructor

use TBETool\PasswordGenerator;

$passwordGenerator = new PasswordGenerator($length, $count, $characters);

Parameter Details

$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

Supported Characters

  1. lower_case
  2. upper_case
  3. numbers
  4. special_symbols

Example with parameter

use TBETool\PasswordGenerator;

$passwordGenerator = new PasswordGenerator(16, 5, 'lower_case,numbers,special_symbols');

Set Parameters after creating object

Parameters set during object creation will be overwritten.

# Set lenght of password to 16
# params: (int) length

# Set number of passwords to generate
# params: (int) count

# Set characters to use in password
# params: (string) characters

Generate Password

This will return single password from all passwords generated

@return string of password
$password = $passwordGenerator->generate();

Get All Generated Passwords

@return array of passwords
$passwords = $passwordGenerator->getPasswords();

Get new password from generated passwords

@return string of new password
$password = $passwordGenerator->getPassword();

Get last accessed password

@return string of last password retrieved
$password = $passwordGenerator->getLastPassword();


Anuj Sharma (



You can’t perform that action at this time.