controlabs / password-helper
Helper to encrypt and verify passwords
v1.0.1
2018-10-25 17:56 UTC
Requires (Dev)
- phpstan/phpstan: ^0.10.3
- phpunit/phpunit: ^7.4
This package is auto-updated.
Last update: 2024-10-29 05:34:20 UTC
README
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.