Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks
Laravel password hash and check

How to create hash password in laravel 8 ?

Aman Jain, January 26, 2022January 26, 2022

Laravel provides robust security features and one of them are hash password which is not decryptable. For hashing the password laravel use secure Bcrypt and Argon2 hashing for storing user passwords. Password encrypted with Bcrypt can not be decrypt since it uses key to generate the hashed string and irreversible algorithm.

So in this tutorial i will show you to hashing a password string to store in database and check the password again for login purpose or validating the current password.

Here is the syntax and example

<?php 
use Illuminate\Support\Facades\Hash;
$password= "12345678";
Hash::make($password);

//or using the helper function bycrypt

bcrypt($password);

the above code will generate bcrypt string.

How to check current or database hash password in laravel

As i mentioned above its impossible to decrypt the password since its encrypted with bcrypt algorithm but we can match the plain password string with hashed password in laravel using Hash::check method.

In some cases we need to check our password from database which hashed but we cannot match directly it using equals to operator because stored password is hashed and user input password is plain string so to verify the entered password and stored password is same we use Hash::check method which accepts two parameters first is plain string and second is hashed password string of database.

so simple syntax

Hash::check($request->password,$user->password)

Here is the example to use

<?php

namespace App\Http\Controllers;

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

class UserController extends Controller
{

     /**
     * Show the form to create a new blog post.
     *
     * @return \Illuminate\View\View
     */

    public function login(Request $request)
    {
         
       $user = User::where("email",$request->email)->first();

        if(Hash::check($request->password,$user->password)){
          echo "password match, you can now start session";
        }
        return  "DONE";
   }

Related

Php Laravel bcrypthashlaravelpasswordphp

Post navigation

Previous post
Next post

Related Posts

How to use if else condition in Laravel 8 blade file ?

December 17, 2021January 18, 2022

In this tutorial i will show you to use if else, if and else if in Laravel blade. Laravel use blade engine to render the template and blade have rich features to use conditional statements in file. So here i will show you to use @if, @elseif and @else in…

Read More
Php How to Send Curl Post and Get Request with Headers in Laravel

How to Send Curl Post and Get Request with Headers in Laravel ?

June 11, 2022June 11, 2022

In this article i will show you to send curl post and get request with headers in laravel. As we know curl basically a command line software which used for transferring data between servers and php provides its inbuilt library in php core. In laravel or php to access the…

Read More
Php How to Change Date Format in Laravel

How to Change Date Format in Laravel ?

July 6, 2022November 17, 2023

In this blog we will learn to change date format in laravel. Laravel provides by default two timestamp created_at and updated_at, and there format are according to database format but sometimes we want to show different format across the entire application so In this tutorial we will learn to change…

Read More

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 11
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • June 2025
  • May 2025
  • April 2025
  • October 2024
  • July 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • The Resilience of Nature: How Forests Recover After Fires
  • Understanding Laravel Cookie Consent for GDPR Compliance
  • Understanding High Vulnerabilities: A Critical Overview of the Week of May 12, 2025
  • Installing a LAMP Stack on Ubuntu: A Comprehensive Guide
  • Understanding High Vulnerabilities: A Deep Dive into Recent Security Concerns
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version