tleckie/password

1.0.0 2021-05-08 07:53 UTC

This package is auto-updated.

Last update: 2024-04-11 14:08:51 UTC


README

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