title: Silex : Bad Credentials with custom UserProvider
body: <p>I'm new to Silex, I used <a href="http://asiermarques.com/2013/silex-con-doctrine-dbal-y-orm/" rel="nofollow noreferrer">this tutorial</a> to set up Doctrine ORM.</p>
  
  <p>But now when I'm trying to log in, i got "Bad credentials" error.
  It happens when I use the default "login_check" controller.</p>
  
  <p>If I use a custom one, it works but I don't know how to redirect the user to the page he was looking for. (I tried whith $request->headers->get('referer') in my login controller but it's empty.)</p>
  
  <p>Here's my custom login_check contorller : </p>
  
  <pre><code>$app-&gt;post('/login-check-perso', function(Request $request) use ($app){
  
  $route    = $request-&gt;request-&gt;filter('route');
  $password = $request-&gt;get('_password');
  $username = $request-&gt;get('_email');
  
  
  $userProvider = new \Lib\Provider\UserProvider($app);
  
  $user = null;
  try {
      $user = $userProvider-&gt;loadUserByUsername($username);
  } 
  catch (UsernameNotFoundException $e)
  {
  }
  
  $encoder = $app['security.encoder_factory']-&gt;getEncoder($user);
  
  // compute the encoded password
  $encodedPassword = $encoder-&gt;encodePassword($password, $user-&gt;getSalt());
  
  // compare passwords
  if ($user-&gt;getPassword() == $encodedPassword)
  {
      // set security token into security
      $token = new UsernamePasswordToken($user, $password, 'yourProviderKeyHere', array('ROLE_ADMIN'));
      $app['security']-&gt;setToken($token);
  
      // redirect or give response here
  } else {
      // error feedback
      echo "wrong password";
      die();
  }
  // replace url by the one the user requested while he wasn't logged in
  return $app-&gt;redirect('/web/index_dev.php/admin/');
  })-&gt;bind('login_check_perso');
  </code></pre>
  
  <p>So if someone can explain how to use the default "login_check", or explain to me how can I redirect user to the page he was trying to visit while not logged, it'll be great.</p>
  
  <p>Thanks</p>
  
  <p>EDIT: </p>
  
  <p>I think the "Bad Credentials" is caused by a wrong encoders setting, I used <a href="https://stackoverflow.com/questions/14220229/how-to-attach-a-password-encoder-to-a-user-interface-in-silex">this</a><br>
  to configure mine :</p>
  
  <pre><code>$app['security.encoder.digest'] = $app-&gt;share(function ($app) {
      // use the sha1 algorithm
      // don't base64 encode the password
      // use only 1 iteration
      return new MessageDigestPasswordEncoder('sha1', false, 1);
  });
  
  $app['security.encoder_factory'] = $app-&gt;share(function ($app) {
      return new EncoderFactory(
          array(
              'Symfony\Component\Security\Core\User\UserInterface' =&gt; $app['security.encoder.digest'],
              'Entity\User'                          =&gt; $app['security.encoder.digest'],
          )
      );
  });
  </code></pre>
  
  <p>Is that correct ?</p>