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 –
- Laravel 9 How To Generate UUID in Application Tutorial
- Laravel 9 How to Select Specific Columns in Eloquent Model
- Laravel 9 How To Get All Models From Application Tutorial
- PHP How To Work with Data Pagination Tutorial
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.
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.