title: Symfony2 create own encoder for storing password
body: <p>I'm new to Symfony2 and I have maybe a simple question about encoding my user passwords in my DB.</p>
  
  <p>I'd like to encode and store in DB my users' password that way:</p>
  
  <pre><code>encoded_password = salt . sha1 ( salt . raw_password )
  </code></pre>
  
  <p>I've found various encoders (sha1, sha512, plaintext), I saw that with plaintext I have in my DB raw_password{salt} but I'm still not comfortable with signin/login/getSalt() method in Symfony2.</p>
  
  <p>If you could give me a lift on that (please, assume I do not want to use an existing bundle for UserManagement, I'd like to make my own) it would be AWESOME!</p>
  
  <p>Thanks</p>
  
  <p>EDIT:</p>
  
  <p>I could do that in my signinAction():</p>
  
  <pre><code>$salt = substr(md5(time()),0,10);
  $pwd = $encoder-&gt;encodePassword($user-&gt;getPassword(), $salt);
  $user-&gt;setPassword($salt.$pwd);
  </code></pre>
  
  <p>I could do that in my getSalt():</p>
  
  <pre><code>return substr($this-&gt;password,0,10);
  </code></pre>
  
  <p>But I currently have only that in my loginAction(): (see here: <a href="http://symfony.com/doc/current/book/security.html">http://symfony.com/doc/current/book/security.html</a>)</p>
  
  <pre><code>// src/Acme/SecurityBundle/Controller/Main;
  namespace Acme\SecurityBundle\Controller;
  
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\Security\Core\SecurityContext;
  
  class SecurityController extends Controller
  {
      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);
          }
  
          return $this-&gt;render('AcmeSecurityBundle:Security:login.html.twig', array(
              // last username entered by the user
              'last_username' =&gt; $session-&gt;get(SecurityContext::LAST_USERNAME),
              'error'         =&gt; $error,
          ));
      }
  }
  </code></pre>
  
  <p>How can I tell Symfony2 to check the password during the login action the way I need? (curently doing encode(password,salt) and not salt.encode(password,salt)</p>