Generate Password Hash in Laravel 9

Generate Password Hash in Laravel 9

When implementing authentication in a web application, we may need to hash the user's password. This tutorial shows example how to generate the password hash in Laravel 9 application.

Laravel provides the Hash facade that has the make method which allows hashing a given password.

app/Http/Controllers/TestController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Response;
use Illuminate\Support\Facades\Hash;

class TestController extends Controller
{
    public function index(): Response
    {
        $plaintextPassword = 'pwd123';
        $hashedPassword = Hash::make($plaintextPassword);

        return new Response($hashedPassword);
    }
}

Leave a Comment

Cancel reply

Your email address will not be published.