Blog Detail


Implement HMAC-Bcrypt Password Hashing Function in Laravel cover image

arrow_back Implement HMAC-Bcrypt Password Hashing Function in Laravel

Laravel HMAC Bcrypt contains an implementation of the hmac-bcrypt password hashing function for the Laravel Framework. It is based on the reference implementation created by @epixoip (specifically the PHP one).


If you want to use it, you can use composer:

composer require j3j5/hmac-bcrypt-laravel


On your config/hashing.php you can change the driver to hmac-bcrypt. In order to work, you need to set a pepper which should be a unique (per project) secret string. You have two options, either set HMAC_BCRYPT_PEPPER on your .env or as an environment variable, or add to your own hashing.php config file the following array:

'hmac-bcrypt' => [
    'pepper' => 'black-pepper'

The amount of rounds used by bcrypt is also customizable. You can use HMAC_BCRYPT_ROUNDS on your .env (or as an environment variable) or add the key rounds to the hmac-bcrypt key on your hashing config.

'hmac-bcrypt' => [
    'rounds' => 15


Now you can use it like you would use the hasher on Laravel:

$clearTextPass = 'supersecret';

$hash = Hash::make($clearTextPass);

// Now store it on the db

Later on…

if (Hash::check($clearTextPass, $hash)) {
    // eccoli qua! you can log in your user!

    // Check whether your settings have changed since last time
    if (Hash::needsRehash($hash)) {
        $newHash = Hash::make($clearTextPass);
        // Store the new hash on the db

This package uses the native PHP functions for SHA512 hash_hmac() and crypt() for the Bcrypt encryption (with a salt generated by random_bytes()), so this is not a case of building your own crypto libraries but instead, using the already available ones.

For more details, please visit Github.

Final Notes

If you are an enterprise and want to use develop a CRM, e-commerce, or SAAS web application in Laravel, you must discover an impeccable team with proficiency in the Laravel framework. So Codebrisk is here to help you with your tailored requirements regarding Laravel Development. Our CRM development with Laravel holds a wide range of features for entities to manage their interactions with customers.

So if you have a great idea, then please feel free to contact us or you can launch a project with us.

Published at : 14-10-2022

Author : Rizwan Aslam
Rizwan Aslam

I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.

Launch your project

Launch project