tleckie / password
PHP manager password
Fund package maintenance!
teodoroleckie
www.paypal.com/donate?business=ZHYA2MTGA4884¤cy_code=USD
Requires
- php: ^8
Requires (Dev)
- friendsofphp/php-cs-fixer: v3.0.0-beta.2
- infection/infection: ^0.21.5
- phpunit/phpunit: ^9.5
README
Password hash validator / password requirements validator
Installation
You can install the package via composer:
composer require tleckie/password
Usage
Register user in database:
require_once "vendor/autoload.php"; use Tleckie\Password\Validator; use Tleckie\Password\Requirements; $passwordManager = new Validator(); $validatePasswordForRegistration = 'Secure123.Validator'; //Check if the password meets the requirements to store it. $passwordManager->isValid($validatePasswordForRegistration); // true // You can customize the password requirements $requirements = new Requirements(10, false, true, false, true); $passwordManager = new Validator($requirements); // Generate the hash to be stored in the database (user|hash). $storeInDataBase = $passwordManager->createHash($validatePasswordForRegistration); // User registration completed!
Login:
require_once "vendor/autoload.php"; use Tleckie\Password\Validator; $passwordManager = new Validator(); // Find the user when logging in. $loginPassword = 'Secure123.Validator'; $databaseUserHash = '$2y$08$WiqPWg.Gkd1CPVpCn/izl.DxhAeJCeo8SVpV03vBCb04.OgMEF81m'; // We verify the hash stored in the database with the login passwords $passwordManager->passwordVerify($loginPassword, $databaseUserHash); // true // That's all! I hope this helps you