title: How to encode a password in Symfony 5?
body: <p>I am trying to encode a password in Symfony and after carefully following the documentation <a href="https://symfony.com/doc/current/security.html#c-encoding-passwords" rel="noreferrer">here</a> it still seems like I am doing something wrong. </p>
  
  <p>This is my RegisterController.php:</p>
  
  <pre><code>&lt;?php
      namespace App\Controller;
  
      use App\Entity\User;
      use App\Form\Type\UserType;
      use Symfony\Component\HttpFoundation\Request;
      use Symfony\Component\Routing\Annotation\Route;
      use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
      use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  
  class RegisterController extends AbstractController
  {
  private $passwordEncoder;
  
  public function __construct(UserPasswordEncoderInterface $passwordEncoder)
  {
      $this-&gt;passwordEncoder = $passwordEncoder;        
  }
  
  /**
      * @Route("/register", name="user.register")
      */
  public function create(Request $request)
  {
      $user = new User();
  
      $form = $this-&gt;createForm(UserType::class, $user);
  
      $form-&gt;handleRequest($request);
  
      if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
  
          $user-&gt;setPassword( 
              $this-&gt;passwordEncoder-&gt;encodePassword( $user, $user-&gt;getPassword() )
          );
  </code></pre>
  
  <p>The above returns the following error:</p>
  
  <blockquote>
    <p>Neither the property "plainPassword" nor one of the methods "getPlainPassword()", "plainPassword()", "isPlainPassword()", "hasPlainPassword()", "__get()" exist and have public access in class "App\Entity\User".</p>
  </blockquote>
  
  <p>And here is my Register.twig.html:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;title&gt;{% block title %}Register{% endblock %}&lt;/title&gt;
          {# {% block stylesheets %}{% endblock %} #}
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div class="container"&gt;
              &lt;h2 class="form-signin-heading"&gt;Welcome, please register below&lt;/h2&gt;
              {{ form(form) }}
          &lt;/div&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And finally I have this setup in my <code>security.yaml</code> file:</p>
  
  <pre><code>security:    
     encoders:
          App\Entity\User:
              algorithm: auto
  </code></pre>
  
  <p>I guess it's something simple that I'm overlooking but I couldn't get it to work. It is my first time with <code>Symfony</code>.</p>