PHP code example of yzh52521 / think-hashing

1. Go to this page and download the library: Download yzh52521/think-hashing 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/ */

    

yzh52521 / think-hashing example snippets




declare(strict_types=1);

return [
    'default' => 'bcrypt',
    'driver' => [
        'bcrypt' => [
            'rounds' => env('BCRYPT_ROUNDS', 10),
        ],
        'argon' => [
            'memory' => 1024,
            'threads' => 2,
            'time' => 2,
        ],
        'argon2id' => [
            'memory' => 1024,
            'threads' => 2,
            'time' => 2,
        ],
    ],
];



declare(strict_types=1);

namespace app\controller;

use yzh52521\Hashing\Hash;

class UpdatePasswordController
{
    public function update(Request $request)
    {
        $user['password'] = Hash::make($request->input('new_password'));
        $user->save();
    }
}

$hashed = Hash::make('password', [
    'rounds' => 12
]);

$hashed = Hash::make('password', [
    'memory' => 1024,
    'time' => 2,
    'threads' => 2,
]);

if (Hash::check('plain-text', $hashedPassword)) {
    // 密码匹配…
}

if (Hash::needsRehash($hashed)) {
    $hashed = Hash::make('plain-text');
}

$hasher = Hash::driver('argon2i');
$hasher->make('plain-text');