How to check current password using hash check in Laravel?

Today now in this post i will show you How to check current password using hash check in Laravel? Sometimes we need to working on the change password function on that time we need to check with current password in any version laravel 6, laravel 7 and laravel 8 application. Then current password should be match for change password otherwise it return error with “your old password is wrong”.

Here I mean that i have one form with the three input field like as bellow:

  • current password
  • new password
  • confirm new password

When we make submit form we need to check the current password for match with the store database table password. So, we know in laravel store the hash password, on that way we can’t check directly the equal to condition, But in Laravel provide the Hash facade, Hash::check() method can be help us to do this task.

So we can see the bellow simple example method:

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.');
        dd('Write here your update password code');

Read Also: How to implement infinite ajax scroll pagination in Laravel?

Thanks for read. I hope it help you. For more you can follow us on facebook


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →