title: Symfony 2.1 bad credentials only when encoding the password
body: <p>Here is my code for adding admin user:</p>
  
  <pre><code>public function addAction(Request $request){
      $admin=new Admin();
      $form=$this-&gt;createForm(new AdminType(), $admin);
      if($request-&gt;getMethod()=='POST'){
          $form-&gt;bindRequest($request);
          if($form-&gt;isValid()){
              $factory = $this-&gt;get('security.encoder_factory');
              $encoder = $factory-&gt;getEncoder($admin);
              $password = $encoder-&gt;encodePassword($admin-&gt;getPassword(), $admin-&gt;getSalt());
              $admin-&gt;setPassword($password);
  
              $em=$this-&gt;getDoctrine()-&gt;getEntityManager();
              $em-&gt;persist($admin);
              $em-&gt;flush();
          }
      }
      return $this-&gt;render('PuzzleAdminBundle:Admin:add.html.twig', array(
          'form'=&gt;$form-&gt;createView()
      ));
  }
  </code></pre>
  
  <p>and here is my security.yml:</p>
  
  <pre><code>security:
  encoders:
      Puzzle\AdminBundle\Entity\Admin: sha512
      Symfony\Component\Security\Core\User\User: plaintext
  
  role_hierarchy:
      ROLE_ADMIN:       ROLE_USER
      ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
  
  providers:
      chain_providers:
          chain:
              providers: [admin_db, in_memory]
      admin_db:
          entity: { class: Puzzle\AdminBundle\Entity\Admin, property: username }
      in_memory:
          memory:
              users:
                  root: { password: 123456, roles: [ 'ROLE_SUPER_ADMIN' ] }
  </code></pre>
  
  <p>Everything is OK when i want to login on root, or when I set up entity encoder to plaintext. Why I always get bad credentials when I set up entity encoder to sha512?</p>