title: Symfony 2 security always return Bad Credentials error
body: <p>I've followed the <a href="http://symfony.com/doc/current/book/security.html" rel="nofollow noreferrer">official documentation</a> on using the security provided by symfony 2 standard distribution to authenticate my users, persisting them on the database through Doctrine2, and it seems to be everything ok regarding the configuration, but I always get the same error: <code>Bad Credentials</code>.</p>
  
  <p>I've use the DoctrineFixturesBundle to load some users and roles, and it seems to complete the loading ok. So, I think the problem is somewhere in the authentication process, which is transparent to me... I don't know how to debug this and would appreciate any help...</p>
  
  <p>Thanks! If you need any other code snippet, please let me know, and i'll edit the question. I've not pasted the code here, to make the question more readable....</p>
  
  <p><strong>EDIT 2</strong>: As suggested by <a href="https://stackoverflow.com/users/707968/dieter">@Dieter</a>, I checked the logs, and  it seems no data is passed to the query, which is very weird, since I followed every convention they mention in <a href="http://symfony.com/doc/current/book/security.html#using-a-traditional-login-form" rel="nofollow noreferrer">the cookbook</a>... Here is also the definition of my login form. Sorry for the long question! Any help would be greatly appreciated!</p>
  
  <p>snippet of LoginType.php:</p>
  
  <pre><code>  public function buildForm(FormBuilder $builder, array $options) {
      $builder-&gt;add('_username', 'text', array(
          'label' =&gt; 'Email ',
          'required' =&gt; true,
      ));
      $builder-&gt;add('_password', 'password', array(
          'label' =&gt; 'Password ',
          'required' =&gt; true,
      ));
      $builder-&gt;add('_remember_me', 'checkbox', array(
          'label' =&gt; 'Remember me ',
          'required' =&gt; false,
      ));
    }
  </code></pre>
  
  <p>app/logs/dev.log output:</p>
  
  <pre><code>[2012-04-17 03:43:01] event.DEBUG: Notified event "kernel.request" to listener
                        "Symfony\Component\Security\Http\Firewall::onKernelRequest".
                        [] []
  [2012-04-17 03:43:01] doctrine.DEBUG: SET NAMES UTF8 ([]) [] []
  [2012-04-17 03:43:01] doctrine.DEBUG: SELECT t0.id AS id1, t0.username AS
                        username2, t0.salt AS salt3, t0.password AS password4,
                        t0.is_active AS is_active5, t0.mailer_id AS mailer_id6
                        FROM SfUser t0 WHERE t0.username = ? (["NONE_PROVIDED"])
                        [] []
  [2012-04-17 03:43:01] security.INFO: Authentication request failed: Bad
                        credentials [] []
  [2012-04-17 03:43:01] security.DEBUG: Redirecting to / [] []
  </code></pre>
  
  <p><strong>EDIT</strong>:
  Since my pastebin links expired, and, as suggested by Peter Porfey, this is the code:</p>
  
  <p>This is my security.yml</p>
  
  <pre><code>security:
      encoders:
          ElCuadre\AccountBundle\Entity\User: sha512
  
      role_hierarchy:
          ROLE_ADMIN:       [ROLE_USER, ROLE_PROVIDER]
          ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_PROVIDER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
  
      providers:
          user_db:
              entity: { class: ElCuadre\AccountBundle\Entity\User, property: username}
  
      firewalls:
          dev:
              pattern:  ^/(_(profiler|wdt)|css|images|js)/
              security: false
          secured_area:
              pattern:  ^/
              anonymous: ~
              form_login:
                  login_path: /
                  check_path: /login_check
              logout:
                  path:   /logout
                  target: /
              remember_me:
                key:      %secret%
                lifetime: 3600
                path:     /
                domain:   ~ # Defaults to the current domain from $_SERVER
  
      access_control:
          - { path: ^/$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  </code></pre>
  
  <p>and my controller:</p>
  
  <pre><code>public function loginAction() {
      $request = $this-&gt;getRequest();
      $session = $request-&gt;getSession();
  
      // get the login error if there is one
      if ($request-&gt;attributes-&gt;has(SecurityContext::AUTHENTICATION_ERROR)) {
        $error = $request-&gt;attributes-&gt;get(SecurityContext::AUTHENTICATION_ERROR);
      } else {
        $error = $session-&gt;get(SecurityContext::AUTHENTICATION_ERROR);
        $session-&gt;remove(SecurityContext::AUTHENTICATION_ERROR);
      }
  
      $form = $this-&gt;createForm(new LoginType());
      return $this-&gt;render(
                      'ElCuadreAccountBundle:Auth:login.html.twig',
                       array(
                           'form'         =&gt; $form-&gt;createView(),
                           'last_username' =&gt; $session-&gt;get(
                                                SecurityContext::LAST_USERNAME),
                           'error'       =&gt; $error,
                           )
      );
  }
  </code></pre>
  
  <p>Here is the code of the fixture file:</p>
  
  <pre><code>&lt;?php
  
  namespace ElCuadre\AccountBundle\DataFixtures\ORM;
  
  use Doctrine\Common\Persistence\ObjectManager;
  use Doctrine\Common\DataFixtures\FixtureInterface;
  use Doctrine\Common\DataFixtures\AbstractFixture;
  use ElCuadre\AccountBundle\Entity\User;
  use ElCuadre\AccountBundle\Entity\Role;
  use Symfony\Component\DependencyInjection\ContainerAwareInterface;
  use Symfony\Component\DependencyInjection\ContainerInterface;
  
  class LoadAccountData extends AbstractFixture implements FixtureInterface, ContainerAwareInterface {
  
    private $container;
  
    public function setContainer(ContainerInterface $container = null) {
      $this-&gt;container = $container;
    }
  
    private function loadRole($manager, $name, $roleName) {
      $role = new Role();
      $role-&gt;setName($name);
      $role-&gt;setRole($roleName);
      $manager-&gt;persist($role);
      $manager-&gt;flush();
      return $role;
    }
  
    private function loadUser($manager, $username, $password, $roles) {
      $user = new User();
      $user-&gt;setUsername($username);
      $encoder = $this-&gt;container-&gt;get('security.encoder_factory')-&gt;getEncoder($user);
      $user-&gt;setPassword($encoder-&gt;encodePassword($password, $user-&gt;getSalt()));
      foreach ($roles as $role) {
        $user-&gt;addRole($role);
      }
      $manager-&gt;persist($user);
      $manager-&gt;flush();
    }
  
    public function load(ObjectManager $manager) {
      // Roles:
      $roleUser = $this-&gt;loadRole($manager, 'user', 'ROLE_USER');
      $roleProvider = $this-&gt;loadRole($manager, 'provider', 'ROLE_PROVIDER');
      $roleAdmin = $this-&gt;loadRole($manager, 'admin', 'ROLE_ADMIN');
      $roleSuperAdmin = $this-&gt;loadRole($manager, 'superadmin', 'ROLE_SUPER_ADMIN');
      // Users:
      $this-&gt;loadUser($manager, 'user@elcuadre.com', 'userpass', $roleUser);
      $this-&gt;loadUser($manager, 'provider@elcuadre.com', 'providerpass', $roleProvider);
      $this-&gt;loadUser($manager, 'admin@elcuadre.com', 'adminpass', $roleAdmin);
      $this-&gt;loadUser($manager, 'superadmin@elcuadre.com', 'superadminpass', $roleSuperAdmin);
    }
  }
  </code></pre>