title: Symfony 3 Authentication/Login Form Not Working
body: <p>I am using symfony 3 to create an application that will be used to reserve lanes for a gun range. I have followed the symfony 3 documentation for getting a login and registration form setup and configured. My registration form is working, but my login form does not work. I just get "Invalid Credentials." returned to me no matter what.</p>
  
  <p><strong>Below is my security YML.</strong></p>
  
  <pre><code># To get started with security, check out the documentation:
  # http://symfony.com/doc/current/book/security.html
  security:
      hide_user_not_found: false
      encoders:
          AppBundle\Entity\User:
              algorithm: bcrypt
  
      # http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
      providers:
          our_db_provider:
              entity:
                  class: AppBundle:User
  
      firewalls:
          # disables authentication for assets and the profiler, adapt it according to your needs
          dev:
              pattern: ^/(_(profiler|wdt)|css|images|js)/
              security: false
          main:
              pattern: ^/
              provider: our_db_provider
              form_login:
                  login_path: /login
                  check_path: /login_check
                  csrf_token_generator: security.csrf.token_manager
                  username_parameter: _username
                  password_parameter: _password
              logout: true
              anonymous: true
  
      access_control:
          - { path: ^/profile, roles: ROLE_USER }
          - { path: ^/reservation, roles: ROLE_USER }
  </code></pre>
  
  <p><strong>This is my login controller.</strong></p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Controller;
  
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  use Symfony\Component\HttpFoundation\Request;
  use AppBundle\Form\UserType;
  use AppBundle\Entity\User;
  
  class LoginController extends Controller
  {
      /**
       * @Route("/login", name="login")
       */
      public function loginAction(Request $request)
      {
  
          // loads security utilities
          $authenticationUtils = $this-&gt;get('security.authentication_utils');
  
          // get the login error if there is one
          $error = $authenticationUtils-&gt;getLastAuthenticationError();
  
          // last username entered by the user
          $lastUsername = $authenticationUtils-&gt;getLastUsername();
  
          // renders route
          return $this-&gt;render('default/login.html.twig', [
              'year'      =&gt; date("Y"),
              'error'     =&gt; $error,
              'last_user' =&gt; $lastUsername,
          ]);
      }
  
      /**
       * @Route("/login_check", name="login_check")
       */
      public function loginCheckAction()
      {
      }
  }
  </code></pre>
  
  <p><strong>This is my repository so you can login with either email or username</strong></p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Repository;
  
  use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Doctrine\ORM\EntityRepository;
  
  class UserRepository extends EntityRepository implements UserLoaderInterface {
      public function loadUserByUsername($username)
      {
          $user = $this-&gt;createQueryBuilder('u')
              -&gt;where('u.username = :username OR u.email = :email')
              -&gt;setParameter('username', $username)
              -&gt;setParameter('email', $username)
              -&gt;getQuery()
              -&gt;getOneOrNullResult();
  
          if (null === $user) {
              $message = sprintf(
                  'Unable to find an active admin AppBundle:User object identified by "%s".',
                  $username
              );
              throw new UsernameNotFoundException($message);
          }
  
          return $user;
      } }
  </code></pre>
  
  <p><strong>This is my user Entity</strong></p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Validator\Constraints as Assert;
  use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  use Symfony\Component\Security\Core\User\UserInterface;
  
  /**
   * User
   *
   * @ORM\Table(name="user")
   * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
   */
  class User implements UserInterface, \Serializable
  {
      /**
       * @var int
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
      /**
       * @ORM\Column(type="string", length=25, unique=true)
       */
      private $username;
  
      /**
       * @Assert\NotBlank()
       * @Assert\Length(max = 4096)
       */
      public $plainPassword;
  
      /**
       * @ORM\Column(type="string", length=64)
       */
      private $password;
  
      /**
       * @ORM\Column(type="string", length=60, unique=true)
       */
      private $email;
  
      /**
       * @ORM\Column(name="is_active", type="boolean")
       */
      private $isActive;
  
      public function __construct()
      {
          $this-&gt;isActive = true;
      }
  
      public function getUsername()
      {
          return $this-&gt;username;
      }
  
      public function getSalt()
      {
          return null;
      }
  
      public function getPassword()
      {
          return $this-&gt;password;
      }
  
      public function getPlainPassword()
      {
          return $this-&gt;password;
      }
  
      public function getRoles()
      {
          return array('ROLE_USER');
      }
  
      public function eraseCredentials()
      {
      }
  
      /** @see \Serializable::serialize() */
      public function serialize()
      {
          return serialize(array(
              $this-&gt;id,
              $this-&gt;username,
              $this-&gt;password,
          ));
      }
  
      /** @see \Serializable::unserialize() */
      public function unserialize($serialized)
      {
          list (
              $this-&gt;id,
              $this-&gt;username,
              $this-&gt;password,
          ) = unserialize($serialized);
      }
  
      /**
       * Get id
       *
       * @return integer
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * Set username
       *
       * @param string $username
       *
       * @return User
       */
      public function setUsername($username)
      {
          $this-&gt;username = $username;
  
          return $this;
      }
  
      /**
       * Set password
       *
       * @param string $password
       *
       * @return User
       */
      public function setPassword($password)
      {
          $this-&gt;password = $password;
  
          return $this;
      }
  
      /**
       * Set email
       *
       * @param string $email
       *
       * @return User
       */
      public function setEmail($email)
      {
          $this-&gt;email = $email;
  
          return $this;
      }
  
      /**
       * Get email
       *
       * @return string
       */
      public function getEmail()
      {
          return $this-&gt;email;
      }
  
      /**
       * Set isActive
       *
       * @param boolean $isActive
       *
       * @return User
       */
      public function setIsActive($isActive)
      {
          $this-&gt;isActive = $isActive;
  
          return $this;
      }
  
      /**
       * Get isActive
       *
       * @return boolean
       */
      public function getIsActive()
      {
          return $this-&gt;isActive;
      }
  }
  </code></pre>
  
  <p>Not sure whats going on, but I would really appreciate some help.</p>
  
  <p>Thanks,
  Robert</p>