How to Compare current password with hash password in Laravel

  1542 views   6 months ago Laravel

In this article we will share with you how to check your current password string with laravel's hash generated password help of hash::check() function. we know laravel store password in hash formate so password not seen in readable formate. so, how to check any string with that hash converted laravel's password string?

Many times you need to compare any password string with laravel's olds password hash string. this is needed when we built password change functionality in an application. before changes password, we want to check the user put the string in the input box that is matched with his/her old password string?

You can be done it help of Hash::check() function in your laravel application.

Example

public function changePassword(Request $request)
{
    $input = $request->all();
    $user = User::find(auth()->user()->id);
    // Check password string with hash string..
    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');
    }
}

As you can see, how to check your current password string with your old one laravel's hash password in your laravel application help of Hash::check() function.

We hope that small tutorials help everyone. if you have known more ways to check the current password with an old password in laravel or any issues or questions related to these tutorials so please comment below.

Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]