PHP code example of controlabs / password-helper

1. Go to this page and download the library: Download controlabs/password-helper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

controlabs / password-helper example snippets


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();

use Controlabs\Http\Exception\Unauthorized; // composer per = 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.');
}