2 years ago

#20794

test-img

Swim89

Laravel reset password using Username instead Email

I would to reset the password in my project using the Username field instead the Email one.

I already set login with username field and it works, but not the same for resetting password.

I overrode methods on ResetPasswordController with some instructions get online but I can't solve my issue.

Here my code:

class ResetPasswordController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Password Reset Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling password reset requests
    | and uses a simple trait to include this behavior. You're free to
    | explore this trait and override any methods you wish to tweak.
    |
    */

    use ResetsPasswords;

    /**
     * Where to redirect users after resetting their password.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    protected function credentials(Request $request)
    {
        return $request->only(
            'username', 'password', 'password_confirmation', 'token'
        );
    }

    protected function rules()
    {
        return [
            'token' => 'required',
            'username' => 'required',
            'password' => 'required|confirmed|min:8',
        ];
    }
}

I also changed resources/views/auth/passwords/reset.blade.php and resources/views/auth/passwords/email.blade.php overriding username to all email input fields.

Laravel version: 7.x

Any suggestions?

php

laravel

authentication

laravel-7

reset-password

0 Answers

Your Answer

Accepted video resources