Backend Development 3 min read

Using Laravel's Hash Facade for Password Hashing and Verification

This guide explains how to use Laravel's Hash facade to securely hash passwords with Bcrypt or Argon2, configure hashing drivers, adjust algorithm parameters, and verify or rehash passwords using methods such as make, check, and needsRehash.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Using Laravel's Hash Facade for Password Hashing and Verification

Laravel's Hash facade provides secure Bcrypt and Argon2 hashing for storing user passwords; when using the built‑in LoginController and RegisterController , Bcrypt is used by default for registration and authentication.

The default hashing driver is defined in config/hashing.php and can be either Bcrypt or Argon2 . Note that the Argon2 driver requires PHP 7.2.0 or higher.

To hash a password you call the make method on the Hash facade. Example controller code:

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Http\Controllers\Controller;

class UpdatePasswordController extends Controller
{
    /**
     * Update user password.
     */
    public function update(Request $request)
    {
        // Validate new password length...
        $request->user()->fill([
            'password' => Hash::make($request->newPassword)
        ])->save();
    }
}

For Bcrypt you can adjust the cost factor with the rounds option:

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

For Argon2 you can control memory , time , and threads options:

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

To verify a plain‑text password against a stored hash, use Hash::check :

if (Hash::check('plain-text', $hashedPassword)) {
    // Password matches
}

When the hashing parameters change, Hash::needsRehash tells you whether a stored hash should be regenerated:

if (Hash::needsRehash($hashed)) {
    $hashed = Hash::make('plain-text');
}
PHPhashLaravelbcryptpasswordArgon2
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.