I am trying to check if entered password is currently logged in users password and give error message if not.
I have profile editing form with name, email etc.
Last input in form is password input.
How can I check if password that is entered is current password?
In EditProfileRequest i tried (custom request file, made with artisan):
public function rules() {
return [
'first_name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users,email,'.Auth::user()->id,
'country_code' => 'digits_between:1,4|numeric',
'phone' => 'digits_between:5,12|numeric',
'password' => 'required|confirmed',
];
}
but it rejected form with correct password. Then I tried adding to controller this part:
if (!Hash::check(Input::get('password'), Auth::user()->password)) {
return Redirect::back()->withInputs();
}
this worked but I don't get any errors for user and I don't know how to add custom error messages, since I am using built-in validator.
if (!Hash::check(Input::get('password'), Auth::user()->password)) { return Redirect::back()->withErrors(['password' => 'Incorrect password']); }