how do you reset the password? it should not interfere with guard or csrf
How to Change CSRF token and /or Session Data After Password Change ?
I have built a feature where a user can change their password after having logged in. (I am aware of reset pw feature, however that assumes you are not yet logged in yet.)
Ok - so I have my change password view working great. Also my change pw controller is working great. My controller checks the old password from the DB against the submitted pw in the form and then proceeds to hash and save a new pw. All Good !
Problem: Once the password has been changed, if I now go to another page on the site, Laravel kicks me out to the login page. I am guessing that this is because there is a now mismatch either with the CSRF token or perhaps more likely, the default web guard session data as created within the config/Auth. I don't know either way.
Any ideas nad help as to what I need to do to ensure that once a pw change has occured that the user will not get kicked out ?
Many thanks !
I can't see anything in your code that might affect the session, therefore you should not be logged out.
You get the user (a long-winded, redundant way since Auth already has the user) - but that should not cause an issue
You use the php password_verify function which knows nothing about your sessions
You replace the password, save the user and return a view. Here I would redirect instead, but that should not be the issue.
???
refactored to simplify the problem a little
public function password_update(Request $request)
{
$this->validate($request,
[
'old_password' => 'required',
'new_password' => 'required',
'new_password2' => 'required|same:new_password',
]);
if (!password_verify($request->old_password,$request->user->password)) {
flash::error('The Old Password is Not Valid');
return back();
}
$request->user()->fill([
'password' => Hash::make($request->new_password)
])->save();
flash::success('Password has been updated');
return redirect('/contractor_portal'); //or wherever
}
Please or to participate in this conversation.