PHP Classes

PHP Password Generator Class Toolbox: Generate, analyze and create hashes of passwords

Recommend this page to a friend!
  Info   View files Example   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 162 This week: 1All time: 8,931 This week: 560Up
Version License PHP version Categories
php-password-toolbox 1.0.0Custom (specified...5PHP 5, Text processing, Security
Description 

Author

This package can generate, analyze and create hashes of passwords.

It can generate a string that can be used as a password which may optionally be readable by people.

The package also generate a hash for the password, so it can be verified later if a given password entered by a user matches what the original password.

It may also analyze the password to tell if it matches certain characteristics like a certain length, types of characters that it contains or if it is already in a dictionary file of commonly used passwords.

Picture of Enrico Sola
Name: Enrico Sola <contact>
Classes: 5 packages by
Country: Italy Italy
Age: 30
All time rank: 3209121 in Italy Italy
Week rank: 416 Up16 in Italy Italy Up

Example

<?php
require dirname(__FILE__) . '/php-password-toolbox.php';

//Generating a password.
$generator = new PHPPasswordToolBox\Generator();
$password = $generator->generate(12);
echo
'Random password: ' . $password . PHP_EOL;

//Generating a human readable password.
$psw = $generator->setDictionaryPath(dirname(__FILE__) . '/dictionary.txt')->generateHumanReadable(12, 2);
echo
'Human readable password: ' . $psw . PHP_EOL;

//Analyzing password.
$analyzer = new PHPPasswordToolBox\Analyzer();
$analysis = $analyzer->analyze($password);
var_dump($analysis);

//Complete password analysis.
$analysis = $analyzer->setDictionaryPath(dirname(__FILE__) . '/rockyou.txt')->completeAnalysis($password);
var_dump($analysis);

//Creating a hash from the password.
$hash = PHPPasswordToolBox\Hash::createSimpleHash($password);
var_dump($hash);

//Comparing the created hash with the original password.
$result = PHPPasswordToolBox\Hash::compareSimpleHash($password, $hash);
var_dump($result);

//Creating a more complex hash.
$hash = PHPPasswordToolBox\Hash::createHash($password);
var_dump($hash);

//Comparing the new hash with the original password.
$result = PHPPasswordToolBox\Hash::compareHash($password, $hash);
var_dump($result);
?>


Details

Password toolkit (PHP edition)

Password toolkit is a simple library that will help you handling passwords with PHP without any dependencies. This library is a PHP porting from the "Password toolkit" library available for Node.js. You can use this library to generate suggested passwords, analyse user provided passwords in order to get a strength score and create a hash that can be stored within the database. Note that this library require PHP version 7.0 or greater.

Password analysis

First, you need to create an instance of the "Analyzer" class as following:

$analyzer = new PHPPasswordToolBox\Analyzer();

Simple analysis:

$analyzer->analyze($password);

Complete analysis:

$analyzer->setDictionaryPath('rockyou.txt')->completeAnalysis($password);

Note that the complete analysis require a dictionary containing a list of weak passwords, passwords in this list must be separated by a break line (\n). You can download dictionaries here. Both methods will return an associative array containing informations about chars count, keywords and the score.

Password generation

First, you need to create an instance of the "Generator" class as following:

$generator = new PHPPasswordToolBox\Generator();

Random password:

$generator->generate(12);

Human readable password generation:

$generator->setDictionaryPath('dictionary.txt')->generateHumanReadable(12, 2);

Note that in order to generate human readable passwords you need a dictionary, words in the dictionary must be separated by a break line (\n). If you are looking for an English word list, give a look here.

Password hashing

Simple hash generation:

PHPPasswordToolBox\Hash::createSimpleHash($password);

More complex hash generation:

PHPPasswordToolBox\Hash::createHash($password);

The first method will return the hash as a string, the second one will return an associative array with the hash and its parameters (salts, algorithm, loop number). If you need to compare a given password and a hash generated with the first method you can use this method:

PHPPasswordToolBox\Hash::compareSimpleHash($password, $hash);

While if you used the second method you can do this:

PHPPasswordToolBox\Hash::compareHash($password, $hash);

Are you looking for the Node.js version? Give a look here.


  Files folder image Files  
File Role Description
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file demo.php Example Example script
Accessible without login Plain text file LICENSE.md Lic. License text
Plain text file php-password-toolbox.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:162
This week:1
All time:8,931
This week:560Up