title: class PasswordEncoderSubsciber implements EventSubscriberInterface
body: <p>When I create a user via a Post request thanks to Api platflorm, I want the transmitted password to be hashed before being inserted into a database ...</p>
  <p>For the moment, the user is well created in bdd but password is always in clear. My subscriber therefore seems to be zapped ... but I don't understand why or how to debug ...</p>
  <p>If someone has a lead I'm interested</p>
  <p>my code</p>
  <pre><code>&lt;?php
  
  namespace App\Events;
  
  use ApiPlatform\Core\EventListener\EventPriorities;
  use App\Entity\User;
  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  use Symfony\Component\HttpKernel\Event\ViewEvent;
  use Symfony\Component\HttpKernel\KernelEvents;
  use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  
  class PasswordEncoderSubsciber implements EventSubscriberInterface
  {
      /**
       * @var UserPasswordEncoderInterface
       */
      private $encoder;
  
      public function __construct(UserPasswordEncoderInterface $encoder)
      {
          $this-&gt;encoder = $encoder;
      }
  
      public static function getSubscribedEvents()
      {
          return [
              KernelEvents::VIEW =&gt; ['encodePassword', EventPriorities::PRE_WRITE],
          ];
      }
  
      public function encodePassword(ViewEvent $event): void
      {
          $user = $event-&gt;getControllerResult();
          dd($user);
          $method = $event-&gt;getRequest()-&gt;getMethod();
          if ($user instanceof User &amp;&amp; 'POST' === $method) {
              $hash = $this-&gt;encoder-&gt;encodePassword($user, $user-&gt;getPassword());
              $user-&gt;setPassword($hash);
          }
      }
  }
  </code></pre>