title: Symfony 4 Simple Form Authentication With Constraint Validator
body: <p>I want to use ConstraintValidator in my custom login authentication (using SimpleForm) to validate google Recaptcha of this bundle <a href="https://github.com/excelwebzone/EWZRecaptchaBundle" rel="nofollow noreferrer">EWZRecaptchaBundle</a> I have not an idea</p>
  
  <p><code>security.yaml</code> main firewall section:</p>
  
  <pre><code>    providers:
           default:
               entity:
                   class: App:User
                   property: phone
      main:
           pattern: ^/
           anonymous: ~
           provider: default
           simple_form:
                 authenticator: App\Security\Authenticator\UserAuthenticator
                 check_path: login
                 login_path: login
                 username_parameter: phone
                 password_parameter: password
                 use_referer: true
           logout:
                 path: logout
  </code></pre>
  
  <p>I need to use <a href="https://github.com/excelwebzone/EWZRecaptchaBundle/blob/master/src/Validator/Constraints/IsTrue.php" rel="nofollow noreferrer">Validaitor</a> in <code>App\Security\Authenticator\UserAuthenticator</code></p>
  
  <p>This is my Custom Authenticator (<code>App\Security\Authenticator\UserAuthenticator</code>):
      
  
  <pre><code>//...
  
  class UserAuthenticator implements SimpleFormAuthenticatorInterface
  {
      private $encoder;
  
      public function __construct(UserPasswordEncoderInterface $encoder)
      {
          $this-&gt;encoder = $encoder;
      }
  
      public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
      {
          try {
              $user = $userProvider-&gt;loadUserByUsername($token-&gt;getUsername());
          }
          catch (UsernameNotFoundException $exception) {
              throw new CustomUserMessageAuthenticationException("invalid");
          }
  
          $isPasswordValid = $this-&gt;encoder-&gt;isPasswordValid($user, $token-&gt;getCredentials());
          if ($isPasswordValid) {
              return new UsernamePasswordToken($user, $user-&gt;getPassword(), $providerKey, $user-&gt;getRoles());
          }
  
          throw new CustomUserMessageAuthenticationException("invalid");
      }
  
      public function supportsToken(TokenInterface $token, $providerKey)
      {
          return $token instanceof UsernamePasswordToken &amp;&amp; $token-&gt;getProviderKey() === $providerKey;
      }
  
      public function createToken(Request $request, $username, $password, $providerKey)
      {
          return new UsernamePasswordToken($username, $password, $providerKey);
      }
  }
  </code></pre>