Skip to content

⚡ PHP password hash validator / password requirements validator

License

Notifications You must be signed in to change notification settings

teodoroleckie/password

Repository files navigation

PHP password manager - Password hash validator / password requirements validator

Password hash validator / password requirements validator

Scrutinizer Code Quality Build Status Total Downloads Code Intelligence Status

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