Laravel Create Password Hash Code Example

Aug 08, 2022 . Admin

Hello Friends,

Today, Laravel Create Password Hash Code Example is our main topic. I explained simply step by step laravel generate password hash. This post will give you simple example of how to make hash password in laravel. let’s discuss about how to get hash password in laravel. you will do the following things for laravel hash password example.

In this post, to save a password into db you need to encrypt it so, from a plain password you'll encrypt it using Hash::make('passwordstring'); and then save this hashed password in the database.

You can use this example with laravel 6, laravel 7, laravel 8 and laravel 9 version.

So, let's follow few step to create example of laravel hash password example.

Download Laravel

Let us begin the tutorial by installing a new laravel application. if you have already created the project, then skip following step.

composer create-project laravel/laravel example-app
Generate Hash Password in Controller File: Example 1 :
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Hash;

class PostController extends Controller
{
    /**
     * Write Your Code..
     *
     * @return string
    */
    public function store(Request $request)
    {
        $password = Hash::make('nikhilThumar');
        dd($password);
    }
}
Output:
"$2y$10$TqHFFq.0AnRXW8VupixQ/uVeeCuQ/HqnEGU2byBgKQtjh/sF62PAe"
Example 2 :

in this step we genarate uuid using toString() function

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

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

Output:
"$2y$10$pkA..onw7nRJaIePHbFbR.T9m6Y/AwkeroDplmYXuWh/d.zajVLrO"

now it works...

I hope it can help you...

#Laravel