Skip to content
This repository was archived by the owner on Nov 3, 2024. It is now read-only.

controlabs/php-password-helper

Repository files navigation

php-password-helper

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.

About

PHP helper to encrypt and verify passwords

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages