I use hash check to compare between current password which is inputted by the user and current password which is stored in the database (Bcrypt)
Here is my source code
$user = User::findOrFail($request->id);
if (Hash::check($request->password, $user->password)) {
$user->fill([
'password' => Hash::make($request->newPassword)
])->save();
$request->session()->flash('success', 'Password changed');
// return redirect()->route('your.route');
echo "Hash match";
} else {
$request->session()->flash('error', 'Password does not match');
// return redirect()->route('your.route');
echo "Hash does not matched";
}
My problem is the Hash:check always return false ("Hash does not matched")
I put the variable in hash check like this
Hash::check(new password plain text, bcrypt value in db)
Before the Hash check is called. I try to print the variable to investigate why it not working. I found my plain text of the new password is already sent and I already got the bcrypt password from the database as well. Everything looks fine it should be worked. I don't know what is my mistake. I follows a lot of topic on this site to solve my problem as I tried it does not work for me. Anyone, please help me.
Thank you.
If you are using this with default Login Controller provided by auth,then you need not use this. Its automatically done by laravel itself.
You're using the wrong argument order.
Try this,
if (Hash::check($user->password, $request->password))