Download .zip |
Info | Documentation | View files (19) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2020-08-01 (21 hours ago) | Not yet rated by the users | Total: 71 This week: 8 | All time: 9,651 This week: 30 |
Version | License | PHP version | Categories | |||
password-helper 1.0.1 | The PHP License | 5 | PHP 5, Validation, Security |
Description | Author | |
This package can generate and check a password according to rules. |
A PHP library that makes using best practices with passwords easy _by default_.
Note: There is a PHP 5 compatible version available.
Simply add a dependency on stymiee/password-helper
to your project's composer.json
file if you
use Composer to manage the dependencies of your project.
Here is a minimal example of a composer.json
file that just defines a dependency on Password Helper:
{
"require": {
"stymiee/password-helper": "^2"
}
}
To use the PHP 5 compatible version, use version 1.*:
{
"require": {
"stymiee/password-helper": "^1"
}
}
To configure your Password Helper to suit your business requirements, you can set your password policy when creating your Password Helper object. There are six factors you can configure be required (or not) and, if required, the minimum criteria for that password characteristic. They are:
If you do not pass any custom policy rules when creating your Password Helper it will default to the values listed above.
$passwordHelper = new Password();
is equivalent to:
$passwordHelper = new Password([
'minimumLetters' => 1,
'minimumDigits' => 1,
'minimumLowercase' => 1,
'minimumUppercase' => 1,
'minimumSpecialChars' => 1,
'minimumLength' => 10
]);
To modify a policy you can pass it by name, with its custom value, to the constructor. The code below sets all the rules to require two of each type and sets a minimum password length of twelve characters.
$passwordHelper = new Password([
'minimumLetters' => 2,
'minimumDigits' => 2,
'minimumLowercase' => 2,
'minimumUppercase' => 2,
'minimumSpecialChars' => 2,
'minimumLength' => 12
]);
You only need to pass a custom value when you change its value from the default value. The code below only changes the
values for minimumDigits
and minimumLength
.
$passwordHelper = new Password([
'minimumDigits' => 2,
'minimumLength' => 12
]);
To remove a requirement give it a value of zero.
$passwordHelper = new Password([
'minimumSpecialChars' => 0 // Special characters are not required
]);
$password = (\PasswordHelper\new Password())->generate(); // 8TpKC>&nQA
$password = \PasswordHelper\new Password();
echo var_dump($password->validateComplexity('!aa34sDDdfg7dfgdsfg2gg'));
echo var_dump($password->validateComplexity('1234'));
Outputs
true
false
$password = \PasswordHelper\new Password();
echo $password->checkStrength('a');
echo $password->checkStrength('qr193');
echo $password->checkStrength('8TpKC>&nQA');
Outputs
Very Weak
Good
Very Strong
$hashedPassword = (\PasswordHelper\new Password())->hash('secret1234');
$password = \PasswordHelper\new Password();
if ($password->verify('secret1234', $row['password_hash'])) {
// Let them in
} else {
// Authentication failure
}
$password = \PasswordHelper\new Password();
if ($password->checkForRehash($row['password_hash'])) {
$newHash = $password->hash('secret1234');
// ... then save the new hash ...
}
If you require assistance using this library start by viewing the HELP.md file included in this package. It includes common problems and their solutions.
If you need additional assistance, I can be found at Stack Overflow. Be sure when you ask a question pertaining to the usage of this library be sure to tag your question with the PHP and password tags. Make sure you follow their guide for asking a good question as poorly asked questions will be closed, and I will not be able to assist you.
A good question will include all the following: - A description of the problem (what are you trying to do? what results are you expecting? what results are you actually getting?) - The code you are using (only post the relevant code) - Any error message(s) you are getting
Do not use Stack Overflow to report bugs. Bugs may be reported here.
Files |
File | Role | Description | ||
---|---|---|---|---|
.github (1 directory) | ||||
src (1 directory) | ||||
tests (4 files) | ||||
.editorconfig | Data | Auxiliary data | ||
CHANGELOG | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
CONTRIBUTING.md | Data | Auxiliary data | ||
HELP.md | Data | Auxiliary data | ||
license.txt | Doc. | Documentation | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Documentation | ||
SECURITY.md | Data | Auxiliary data |
Files | / | src | / | PasswordHelper |
File | Role | Description |
---|---|---|
Generator.php | Class | Class source |
Password.php | Class | Class source |
Policy.php | Class | Class source |
StrengthChecker.php | Class | Class source |
Validator.php | Class | Class source |
Files | / | tests |
File | Role | Description |
---|---|---|
GeneratorTest.php | Class | Class source |
PolicyTest.php | Class | Class source |
StrengthCheckerTest.php | Class | Class source |
ValidatorTest.php | Class | Class source |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.