Password Checker
A framework agnostic password checker for PHP., (*1)
Installation
$ composer require acurrieclark/php-password-verifier
Usage
``` php
// include autoloader if you haven't already
include_once('vendor/autoload.php');, (*2)
use acurrieclark\PhpPasswordVerifier\Verifier;, (*3)
// create an instance
$passwordVerifier = new Verifier();, (*4)
// default options are permissive, so each constraint needs to be set as required
$passwordVerifier->setMinLength(8);, (*5)
// constraints can also be chained
$passwordVerifier->setMaxLength(128)->setCheckContainsNumbers(true);, (*6)
// check the password meets the requirements set (min length 8, max length 128, contains numbers), (*7)
$validPassword = $passwordVerifier->checkPassword("passwordToCheck");
```, (*8)
Class Methods
Setting Password Constraints
setMinLength(int $length)
Set the minimum required length of the password, (*9)
setMaxLength(int $length)
Set the maximum allowed length of the password, (*10)
setCheckContainsLetters(boolean $value)
Set the flag to check that the password contains at least one letter, (*11)
setCheckContainsCapitals(boolean $value)
Set the flag to check that the password contains at least one capital letter, (*12)
setCheckContainsNumbers(boolean $value)
Set the flag to check that the password contains at least one number, (*13)
setCheckContainsNumbers(boolean $value)
Set the flag to check that the password contains at least one number, (*14)
setCheckContainsSpecialChrs(boolean $value)
Set the flag to check that the password contains at least one special character from {}()[]#,:;^.?!|&_`~@$%/\\=+-*"'
, (*15)
setCheckBlacklist(boolean $value)
Set the flag to check if the password matches one of the 10000 most popular passwords from https://github.com/danielmiessler/SecLists, (*16)
Checking the Password
checkPassword(string $password)
Verify the password based on the constraints imposed. Returns boolean., (*17)
getErrors()
Returns an array of errors relating to the verified password, (*18)
Utility
getSpecialChrs()
Static: Returns an array of the special characters used to check against when setCheckContainsSpecialChrs(true)
has been set. Handy if you want to warn your users which characters they need to include., (*19)
License
The MIT License (MIT). Please see the License File for more information., (*20)