title: Symfony4 custom password encoder
body: <p>I am upgrading an old application to use Symfony (v4) for the back end and I am stuck trying to get authentication functioning. My database stores hashed passwords and salts for the user, passwords used the <code>crypt</code> php function. I am also using the lexik JWT bundle in an attempt to return a token to the front end.</p>
  
  <p>I cannot get a response other than "bad credentials" from symfony/lexik.</p>
  
  <p>I <strong>think</strong> my problem is rooted in the <strong>encoders</strong> portion, I tried to implement a custom password encoder because crypt uses a modified DES algorithm according to the php docs and simply using the following in my security.yaml does not work.</p>
  
  <pre><code>encoders:
  App\Entity\DB_1\User:
      algorithm: DES
  </code></pre>
  
  <p>Here is my complete security.yaml</p>
  
  <p><strong>security.yaml</strong></p>
  
  <pre><code>security:
  encoders:
      App\Entity\DB_1\User:
          id: 'App\Security\MyPasswordEncoder'
  
  providers:
      entity_provider:
          entity:
              class: App\Entity\MetallicBonds\User
              property: username
  
  firewalls:
      dev:
          pattern: ^/(_(profiler|wdt)|css|images|js)/
          security: false
      login:
          pattern:  ^/login
          stateless: true
          anonymous: true
          json_login:
              check_path: /login_check
              success_handler: lexik_jwt_authentication.handler.authentication_success
              failure_handler: lexik_jwt_authentication.handler.authentication_failure
  
      register:
          pattern:  ^/register
          stateless: true
          anonymous: true
  
      api:
          pattern:  ^/test
          stateless: true
          anonymous: false
          provider: entity_provider
          guard:
              authenticators:
                  - lexik_jwt_authentication.jwt_token_authenticator
  
  access_control:
      - { path: ^/login_check, roles: IS_AUTHENTICATED_ANONYMOUSLY }
      - { path: ^/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
      - { path: ^/test, roles: IS_AUTHENTICATED_FULLY }
  </code></pre>
  
  <p>and my custom password encoder <strong>MyPasswordEncoder.php</strong></p>
  
  <pre><code>namespace App\Security;
  
  use Symfony\Component\Security\Core\Encoder\BasePasswordEncoder;
  use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
  use Symfony\Component\Security\Core\Exception\BadCredentialsException;
  
  class MyPasswordEncoder extends BasePasswordEncoder implements  
  PasswordEncoderInterface
  {
  private $ignorePasswordCase;
  
  public function __construct($ignorePasswordCase = false)
  {
      $this-&gt;ignorePasswordCase = $ignorePasswordCase;
  }
  
  public function encodePassword($raw, $salt)
  {
      // TODO: Implement encodePassword() method.
      return crypt($raw,$salt);
  }
  
  public function isPasswordValid($encoded, $raw, $salt)
  {
      // TODO: Implement isPasswordValid() method.
      if ($this-&gt;isPasswordTooLong($raw)) {
          return false;
      }
  
      try {
          $pass2 = $this-&gt;encodePassword($raw, $salt);
      } catch (BadCredentialsException $e) {
          return false;
      }
  
      if (!$this-&gt;ignorePasswordCase) {
          return $this-&gt;comparePasswords($encoded, $pass2);
      }
  
      return $this-&gt;comparePasswords(strtolower($encoded), strtolower($pass2));
  }
  }
  </code></pre>
  
  <p>I would like to use the currently stored passwords, at least for the moment, so the change from the old system to the new will be smooth for the end users. Has anyone had success using a custom password encoder with Symfony 4?</p>
  
  <p>I should note that when I place an xdebug breakpoint in MyPasswordEncoder.php, it never stops the application, is there somewhere else the class needs to be registered for Symfony to use it?</p>