Support the ongoing development of Laravel.io →
Authentication Security Forms
Last updated 2 years ago.
0

Go into the Auth\PasswordController and look into the trait "ResetsPassword".

0

LukeBro said:

Go into the Auth\PasswordController and look into the trait "ResetsPassword".

Thanks for your reply!

You mean this method right?

vendor\laravel\framework\src\Illuminate\Foundation\Auth

    /**
 * Reset the given user's password.
 *
 * @param  Request  $request
 * @return Response
 */
public function postReset(Request $request)
{
	$this->validate($request, [
		'token' => 'required',
		'email' => 'required|email',
		'password' => 'required|confirmed',
	]);
	$credentials = $request->only(
		'email', 'password', 'password_confirmation', 'token'
	);
	$response = $this->passwords->reset($credentials, function($user, $password)
	{
		$user->password = bcrypt($password);
		$user->save();
		$this->auth->login($user);
	});
	switch ($response)
	{
		case PasswordBroker::PASSWORD_RESET:
			return redirect($this->redirectPath());
		default:
			return redirect()->back()
						->withInput($request->only('email'))
						->withErrors(['email' => trans($response)]);
	}
}

I used this method in my UserController with few changes like below.it's working now. Is this the correct way to do it?

    public function postReset(Request $request)
    {   
            $this->validate($request, [
                    'password' => 'required|confirmed',
            ]);
            $credentials = $request->only(
                    'email', 'password', 'password_confirmation'
            );
            $user = \Auth::user();
            $user->password = bcrypt($credentials['password']);
            $user->save();
            return redirect('user/'.$user->id);
    }

Thanks again!

Last updated 9 years ago.
0

You would also want to validate the email and password_confirmation like in the trait. You should always sanitize and validate ALL input from requests. But other than that yes, and no problem.

Luke

0

Sign in to participate in this thread!

Eventy

Your banner here too?

cagline cagline Joined 16 May 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.