php - How to properly update password in Laravel?
I have a Laravel application where I use a custom user authentication. Now i'm trying to allow user to update their password, the issue I'm running into there is that I need to check for the old password, if the field is not empty than I want to check if the new password matches the password repeat filed, if it does than update it here is the code I have in controller:
$newpass = $request->input('password');
$passrepeat = $request->input('passwordRepeat');
if ($oldPass = $request->input('oldPassword') != null)
{
if (Hash::check($request->oldPassword, auth()->user()->password)){
if ($newpass = $passrepeat){
$password = bcrypt($request['password']);
$user->password = $password;
}
}
}
and then I update it:
$user->update();
But my code seem to not even check for the password field. I'm clearly making mistakes when I check for the oldPassword field. There are just too many options that I can try so I decided ask as a question.
Laravel 5.4
Answer
Solution:
From the docs:
https://laravel.com/docs/5.5/hashing#basic-usage
Answer
Solution:
Just Replace these two lines
With