Laravel 9 How to Make Hash Password Tutorial

Reading Time: 3 minutes
1,909 Views

Inside this article we will see the concept i.e Laravel 9 How to Make Hash Password. Article contains the classified information about generating hashed password in laravel. Laravel provides default methods to generate hashed password in a very easy way.

These hashed password is used to secure the user authentication in a very secure way. Laravel has a class called Hash (It’s a Facade class) and also a helper function called bcrypt which provides method for password hash.

Learn More –

Let’s get started.

Laravel Installation

Open terminal and run this command to create a laravel project.

composer create-project laravel/laravel myblog

It will create a project folder with name myblog inside your local system.

To start the development server of laravel –

php artisan serve

URL: http://127.0.0.1:8000

Assuming laravel already installed inside your system.

Generate Hash Password Using Facade

We will use Facade Hash class to generate hashed password. We will make use of make() a static method from it.

Hash Facade is linked from here:

use Illuminate\Support\Facades\Hash;

Open any of controller from your application.

<?php

namespace App\Http\Controllers;

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

class CustomController extends Controller
{
    /**
     * Write Your Code..
     *
     * @return string
    */
    public function store(Request $request)
    {
        $password = Hash::make("Sanjay Kumar");
        dd($password);
    }
}

We will get output this hashed password –

$2y$10$xtvy7GbXW.DnlP79tmjiQuS6ra1r132vTAcyQvehEeWYDiDZqGr0a

Generate Hash Password Using bcrypt

We will use bcrypt() helper function to generate hashed password. Open any of controller from your application.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class CustomController extends Controller
{
    /**
     * Write Your Code..
     *
     * @return string
    */
    public function store(Request $request)
    {
        $password = bcrypt('Sanjay Kumar');
        dd($password);
    }
}

We will get output this hashed password –

$2y$10$w7ujfU5MSm8SEIeRN8G3ue/3ghMmv/eSbzmjEbnS.OVnW4E4QeHWm

We hope this article helped you to learn Laravel 9 How to Make Hash Password Tutorial in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.