title: Symfony Login error - Invalid credentials
body: <p>I have a form that i want to log a user in - i have loaded fixtures into the database but when i have tried following tutorials i keep getting bad credentials or invalid credentials i will include all my relevant files, if anyone can point anything out that i'm missing id be forever in your debt!</p>
  
  <pre><code> &lt;?php
  
   namespace AppBundle\Forms;
  
   use Symfony\Component\Form\Extension\Core\Type\TextType;
   use Symfony\Component\Form\Extension\Core\Type\PasswordType;
   use Symfony\Component\Form\AbstractType;
   use Symfony\Component\Form\FormBuilderInterface;
   use Symfony\Component\OptionsResolver\OptionsResolver;
   use Symfony\Component\Validator\Constraints\NotBlank;
  
  class LoginType extends AbstractType {
      public function buildForm(FormBuilderInterface $builder, array $options) {
          $builder
              -&gt;add(
                  'username',
                  TextType::class, [
                      'constraints' =&gt; [
                          new NotBlank()
                      ]
                  ]
              )
              -&gt;add(
                  'password',
                  PasswordType::class, [
                      'constraints' =&gt; [
                          new NotBlank()
                      ]
                  ]
              );
      }
  
      public function configureOptions(OptionsResolver $resolver) {
          $resolver-&gt;setDefaults([
              'data_class' =&gt; 'AppBundle\Entity\User'
          ]);
      }
  }
  </code></pre>
  
  <p>and my controller - </p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Controller\Login;
  
  use AppBundle\Entity\User;
  use AppBundle\Forms\LoginType;
  use AppBundle\Repository\UserRepository;
  use Symfony\Component\HttpFoundation\RedirectResponse;
  use Symfony\Component\HttpFoundation\Response;
  use Symfony\Component\Security\Core\Encoder\UserPasswordEncoder;
  use Symfony\Component\Templating\EngineInterface;
  use Symfony\Component\Form\FormFactoryInterface;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Component\Routing\RouterInterface;
  use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  
  class LoginpageController {
      protected $formFactory;
      protected $templating;
      protected $router;
      protected $authenticationUtils;
      protected $encoder;
      protected $userRepository;
  
      public function __construct (
          FormFactoryInterface $formFactory,
          EngineInterface $templating,
          RouterInterface $router,
          AuthenticationUtils $authenticationUtils,
          UserPasswordEncoder $encoder,
          UserRepository $userRepository
      ) {
          $this-&gt;formFactory = $formFactory;
          $this-&gt;templating = $templating;
          $this-&gt;router = $router;
          $this-&gt;authenticationUtils = $authenticationUtils;
          $this-&gt;encoder = $encoder;
          $this-&gt;userRepository = $userRepository;
      }
  
      public function __invoke(Request $request) {
          $user = new User();
          $form = $this-&gt;formFactory-&gt;create(LoginType::class, $user);
          $form-&gt;handleRequest($request);
  
          if($form-&gt;isValid()) {
              return new RedirectResponse (
                  $this-&gt;router-&gt;generate('home'),
                  Response::HTTP_TEMPORARY_REDIRECT
              );
          }
  
          // get the login error if there is one
          $error = $this-&gt;authenticationUtils-&gt;getLastAuthenticationError();
  
          return new Response(
              $this-&gt;templating-&gt;render(
                  'AppBundle:loginpage:loginpage.html.twig', [
                      'form' =&gt; $form-&gt;createView(),
                      'error'         =&gt; $error
                  ]
              )
          );
      }
  }
  </code></pre>
  
  <p>My Form - </p>
  
  <pre><code> {% if error %}
       &lt;div&gt;{{ error.messageKey|trans(error.messageData, 'security') }}&lt;/div&gt;
   {% endif %}
  
    &lt;form method="POST" action="{{ path('login') }}"&gt;
    {{ form_start(form) }}
    {{ form_row(form.username) }}
    &lt;br&gt;
    {{ form_row(form.password) }}
    &lt;br&gt;
    &lt;br&gt;
    &lt;input type="submit" value="submit"/&gt;
    {{ form_end(form) }}
    &lt;/form&gt;
  </code></pre>
  
  <p>My security -</p>
  
  <pre><code>security:
      providers:
          user_database:
              entity:
                  class: AppBundle:User
      encoders:
          AppBundle\Entity\User:
              algorithm: bcrypt
              cost: 11
  
      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:   ^/
             anonymous: ~
             provider: user_database
             form_login:
                login_path: /login
                check_path: /login
             logout:
                path:   /logout
                target: /
  
      access_control:
           - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  </code></pre>
  
  <p>Repo - </p>
  
  <pre><code>&lt;?php
  
  namespace AppBundle\Repository;
  
  use AppBundle\Entity\User;
  use Doctrine\ORM\EntityRepository;
  use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
  use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
  
  class UserRepository extends EntityRepository implements  UserLoaderInterface {
      public function save(User $user) {
          $this-&gt;_em-&gt;persist($user);
          $this-&gt;_em-&gt;flush();
      }
  
      public function delete(User $user) {
          $this-&gt;_em-&gt;remove($user);
          $this-&gt;_em-&gt;flush();
      }
  
      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 = print_r(
                  'Unable to find an active admin AppBundle:User object identified by "%s".',
                  $username
              );
              throw new UsernameNotFoundException($message);
          }
          return $user;
      }
  }
  </code></pre>
  
  <p>ORM mapping - </p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
   &lt;doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"&gt;
  &lt;entity repository-class="AppBundle\Repository\UserRepository" name="AppBundle\Entity\User" table="user"&gt;
  &lt;id name="id" type="guid" column="id"&gt;
    &lt;generator strategy="UUID"/&gt;
  &lt;/id&gt;
  &lt;field name="firstName" type="string" column="first_name" length="255"/&gt;
  &lt;field name="lastName" type="string" column="last_name" length="255"/&gt;
  &lt;field name="email" type="string" column="email" length="255" unique="true"/&gt;
  &lt;field name="username" type="string" column="username" length="255" unique="true"/&gt;
  &lt;field name="password" type="string" column="password" length="4096"/&gt;
  &lt;field name="roles" type="string" column="roles" length="255"/&gt;
  &lt;field name="createdAt" type="datetime" column="createdAt"/&gt;
  &lt;field name="isActive" type="boolean" column="isActive"/&gt;
  &lt;/entity&gt;
  &lt;/doctrine-mapping&gt;
  </code></pre>