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

sylvestero's avatar

TokenMismatchException when I press login button

dear peers, please help me I'm stucked. Each time i press login button after inputting username and password i get error saying

(1/1) TokenMismatchException in VerifyCsrfToken.php (line 68) at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php (line 148)

this is my Login.blade.php source code

Login
{!!Html::style('css/bootstrap.min.css')!!}
{!!Html::style('css/bootstrap-theme.css')!!}
{!!Html::style('css/elegant-icons-style.css')!!}
{!!Html::style('css/font-awesome.css')!!}
{!!Html::style('css/style.css')!!}
{!!Html::style('css/style-responsive.css')!!}
 

<div class="container">

  <form class="login-form" action="{{route('login')}}" method="POST">  
  {!!crsf_field()!!}      
    <div class="login-wrap">
        <p class="login-img"><i class="icon_lock_alt"></i></p>
        <div class="input-group">
          <span class="input-group-addon"><i class="icon_profile"></i></span>
          <input type="text" name="Username" class="form-control" placeholder="Username" autofocus>
        </div>
        <div class="input-group">
            <span class="input-group-addon"><i class="icon_key_alt"></i></span>
            <input type="password" name="password" class="form-control" placeholder="Password">
        </div>
        <label class="checkbox">
            <input type="checkbox" value="remember-me"> Remember me
            <span class="pull-right"> <a href="#"> Forgot Password?</a></span>
        </label>
        <button class="btn btn-primary btn-lg btn-block" type="submit">Login</button>
        <button class="btn btn-info btn-lg btn-block" type="submit">Signup</button>
    </div>
  </form>
 
</div>

loginController.php

0 likes
3 replies
aurawindsurfing's avatar

Check the following:

  1. Your main blade app template. You should have in the section:
<!-- CSRF Token -->
        <meta name="csrf-token" content="{{ csrf_token() }}">

and also

 <!-- Scripts -->
        <script>
            window.Laravel = <?php echo json_encode([
                'csrfToken' => csrf_token(),
            ]); ?>
        </script>

2.Once you do the above it will be included on every pageso you do not have to do it in the forms (correct me if I'm wrong please!) If you use it in your forms then depending on your laravel version

Laravel 4

{{ csrf_field() }}

Laravel 5.

{!!crsf_field()!!}
sylvestero's avatar

@aurawindsurfing thank you. I created another project and started the tutorial afresh but i still have some errors.

(1/1) FatalErrorException Call to a member function hasRole() on null in CheckRole.php (line 19) at FatalErrorException->__construct() in HandleExceptions.php (line 134) at HandleExceptions->fatalExceptionFromError() in HandleExceptions.php (line 119) at HandleExceptions->handleShutdown() in HandleExceptions.php (line 0) at CheckRole->handle() in Pipeline.php (line 148) ..................................................... ...............................................................

aurawindsurfing's avatar

Well that is a different error.

Seems like there is something wrong with your setup if you get that on a new project.

Please or to participate in this conversation.