Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jgravois's avatar

my BOSS can't reset password -- I'm Looking BAD

I am getting a "The token field is required.” error when trying to reset a password. I have BOTH versions of the csrf setter in password.blade.php (I tried each separately and now both). I am using the HTML/Collective.

{!! Form::open(['role' => 'form', 'url' => '/password/email', 'class' => 'form-horizontal']) !!}
{!! Form::token() !!}
{!! csrf_field() !!}

Ialso have this in the VerifyCsrfToken middleware. Earlier I tried to delete the $middleware from App\Kernal.php and still was getting the error.

class VerifyCsrfToken extends BaseVerifier
{
   /**
    * The URIs that should be excluded from CSRF verification.
    *
    * @var array
    */
   protected $except = [
       '/password/reset'
   ];
}
0 likes
12 replies
thomaskim's avatar
Level 41

This has nothing to do with csrf token and has everything to do with not passing the password token.

In the reset stub, you'll see this line of code:

<input type="hidden" name="token" value="{{ $token }}">

You don't have that, and yes, it is different from the csrf_token.

Also, in the ResetsPassword file, you'll see this:

protected function getResetValidationRules()
{
    return [
        'token' => 'required',
        'email' => 'required|email',
        'password' => 'required|confirmed|min:6',
    ];
}

You'll see that the token is required.

Also, in the CreatePasswordResetsTable migration file, you'll see that one of the fields in the password_resets column is the token.

Basically, the token is used to figure out if the user trying to reset the password is valid. It checks to see if an email with that token exists in the password_resets table.

2 likes
jgravois's avatar
<form method="POST" action="http://www.team-adc.com/password/reset" accept-charset="UTF-8" role="form”>
    <input name="_token" type="hidden" value="fjovdy0teDQcebc1wiaTIS3S7ovjFU3UfALqjUek">
    <input type="hidden" name="_token" value="fjovdy0teDQcebc1wiaTIS3S7ovjFU3UfALqjUek">
    <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-user"></i></span>
            <input type="email" class="form-control" placeholder="Email Address" name="email" value="jgravois@uaminc.com">
    </div>
    <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-key"></i></span>
             <input type="password" class="form-control" placeholder="Password" id="password" name="password">
    </div>
    <div class="input-group">
        <span class="input-group-addon"><i class="fa fa-check-square"></i></span>
            <input type="password" class="form-control" placeholder="Confirm Password" id="password_confirmation" name="password_confirmation">
    </div>
    <div class="row">
        <div class="col-xs-12">
            <button type="submit" class="btn btn-success col-xs-12">Reset Password</button>
         </div>
    </div>
</form>
Snapey's avatar

token field required is not the csrf token

Password reset involves sending the user a one-time token that they click on. This then brings them to your site, and the token is passed to the reset password function.

You then need to send the password to the reset form (the token field).

So, you should have a field on your form like;

<input type="hidden" name="token" value="{{ $token }}">

The token is passed to the form in the resetsPasswords trait like;

    public function showResetForm($token = null)
    {
        if (is_null($token)) {
            return $this->getEmail();
        }

        if (view()->exists('auth.passwords.reset')) {
            return view('auth.passwords.reset')->with('token', $token);
        }

        return view('auth.reset')->with('token', $token);
    }
jgravois's avatar

@thomaskim now I get Undefined variable: token (View: /var/www/team-adc.com/resources/views/auth/password.blade.php)

AdrianB's avatar

Try {{ Session::token() }} instead of {{ $token }}

There is also a helper function that will fetch it for you: {{ csrf_token() }}

My personal preference is to use the form builder for my forms. https://github.com/LaravelCollective/html

When you use {!! Form::open() !!} it includes the token for you.

jgravois's avatar

it would HELP if I put that in reset.blade.php instead of password.blade.php.

thomaskim's avatar

@jgravois Check out what @Snapey posted. That's the default way of handling things. If you don't have a token, you show the password reset link form (a form where a user inputs his email, then you email the link to the reset form). If you do have a token, you show the form where the user enters his new password and resets it.

Edit: Nvm. I guess you figured it out. :)

Snapey's avatar

@AdrianB -- its NOT the csrf token that it is missing. Its the password reset token, which should be in a hidden field.

@jgravois - see my post for how the out of the box does it. The token is grabbed from the user's initial request and then sent to the form using ->with('token', $token);

AdrianB's avatar

My bad, just read CSRF token not working and went with that.

Please or to participate in this conversation.