PHP code example of zhuchunshu / hyperf-hashing

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

    

zhuchunshu / hyperf-hashing example snippets




declare(strict_types=1);

return [
    'default' => 'bcrypt',
    'driver' => [
        'bcrypt' => [
            'class' => \HyperfExt\Hashing\Driver\BcryptDriver::class,
            'rounds' => env('BCRYPT_ROUNDS', 10),
        ],
        'argon' => [
            'class' => \HyperfExt\Hashing\Driver\Argon2IDriver::class,
            'memory' => 1024,
            'threads' => 2,
            'time' => 2,
        ],
        'argon2id' => [
            'class' => \HyperfExt\Hashing\Driver\Argon2IdDriver::class,
            'memory' => 1024,
            'threads' => 2,
            'time' => 2,
        ],
    ],
];



declare(strict_types=1);

namespace App\Http\Controller;

use Hyperf\HttpServer\Request;
use HyperfExt\Hashing\Hash;

class UpdatePasswordController
{
    public function update(Request $request)
    {
        // ……

        $user->fill([
            'password' => Hash::make($request->input('new_password'))
        ])->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::getDriver('argon2i');
$hasher->make('plain-text');
shell script
php bin/hyperf.php vendor:publish zhuchunshu/hyperf-hashing