ItSolutionStuff.com

How to Check Current Password using Hash Check in Laravel?

By Hardik Savani • April 16, 2024
Laravel

Sometimes we are working on change password function at that time we require to check with current password in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 app. If current password should be match otherwise return error with "your old password is wrong".

I mean we have one form with three input field like as bellow:

1)current password

2)new password

3)confirm new password

When it will submit form we have to check current password match with store database table password. So, laravel store hash password, that way we can't check directly equal to condition, But Laravel provide Hash facade, Hash::check() method will help you to do this task.

You can see bellow simple example method:

Example:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Hash;

class PasswordController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function changePassword(Request $request)

{

$input = $request->all();

$user = User::find(auth()->user()->id);

if(!Hash::check($input['current_password'], $user->password)){

dd('Return error with current passowrd is not match.');

}else{

dd('Write here your update password code');

}

}

}

It can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel 10 React JS Auth Scaffolding Tutorial

Read Now →

Laravel 10 Authentication using Breeze Tutorial

Read Now →

Laravel Google 2FA Authentication Tutorial Example

Read Now →

Laravel Two Factor Authentication using Email Tutorial

Read Now →

How to Add Two Factor Authentication with SMS in Laravel?

Read Now →

Laravel Custom Email Verification System Example

Read Now →

Laravel Custom Forgot & Reset Password Example

Read Now →

Laravel Custom Login and Registration Example

Read Now →

Laravel Sanctum SPA API Authentication Example

Read Now →

Laravel Firebase Push Notification Tutorial

Read Now →

Laravel Model Events Tutorial

Read Now →

Laravel Livewire Add or Remove Dynamically Input Fields Example

Read Now →

Laravel Eloquent orderByRaw() Query Example

Read Now →

Laravel Livewire CRUD Application Tutorial

Read Now →

Laravel Login with Google Account Tutorial

Read Now →