controlabs/password-helper

Helper to encrypt and verify passwords

v1.0.1 2018-10-25 17:56 UTC

This package is auto-updated.

Last update: 2024-10-29 05:34:20 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Build Status Code Intelligence Status PHPStan

License Latest Stable Version Latest Unstable Version composer.lock Total Downloads

Helper to encrypt and verify passwords.

Installation

composer require controlabs/password-helper

Usage

Encrypting password
use Controlabs\Helper\Password as PasswordHelper;

$helper = new PasswordHelper();

$passwordData = $helper->encrypt($_POST['password']);

$user = new User();
$user->login = 'controlabs';
$user->password = $passwordData->password();
$user->password_salt = $passwordData->salt();
$user->save();
Verify password
use Controlabs\Http\Exception\Unauthorized; // composer require controlabs/http-exceptions (optional)
use Controlabs\Helper\Password as PasswordHelper;

$helper = new PasswordHelper();

$user = User::findByLogin('login', $_POST['login']);

$accept = $user and $helper->verify($user->password, $_POST['password'], $user->password_salt);

if(!$accept) {
    throw new Unauthorized('Invalid login or password.');
}

License

This software is open source, licensed under the The MIT License (MIT). See LICENSE for details.