title: how to hash user password in symfony 5.2.6 when using security.yaml and make:user command
body: <p><strong>Versions I Used</strong>:
  using (symfony 5.2.6) with (api-platform 2.7.0)  alongside (php 8.0.3) and (postgres 13)</p>
  <p><strong>Description</strong>
  used maker bundle to generate a User Entity and configured the security.yaml to encode passwords already tried auto and bcrypt or even argon2i non of them seems to work and hash the passwords</p>
  <p><strong>Possible Solution</strong>
  as the symfony documentation describes it should automatically encode passwords if we are using security bundle and implementing UserInterface but this one seems like a bug cause i have tried many things nothing works . maybe using UserPasswordEncoderInterface but this one should not be used when User class is implementing UserInterface anyway i hope someone check this and tell me i'm wrong otherwise seems like a bug.</p>
  <p>security.yaml:</p>
  <pre class="lang-yaml prettyprint-override"><code>security:
      encoders:
          App\Entity\User:
              algorithm: bcrypt
  
      # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
      providers:
          # used to reload user from session &amp; other features (e.g. switch_user)
          app_user_provider:
              entity:
                  class: App\Entity\User
                  property: username
      firewalls:
          dev:
              pattern: ^/(_(profiler|wdt)|css|images|js)/
              security: false
          main:
              anonymous: true
              lazy: true
              provider: app_user_provider
  
              # activate different ways to authenticate
              # https://symfony.com/doc/current/security.html#firewalls-authentication
  
              # https://symfony.com/doc/current/security/impersonating_user.html
              # switch_user: true
  
      # Easy way to control access for large sections of your site
      # Note: Only the *first* access control that matches will be used
      access_control:
          # - { path: ^/admin, roles: ROLE_ADMIN }
          # - { path: ^/profile, roles: ROLE_USER }
  
          # or require ROLE_ADMIN or IS_AUTHENTICATED_FULLY for /admin*
          # - { path: '^/admin', roles: [IS_AUTHENTICATED_FULLY, ROLE_ADMIN] }
  
          # the 'path' value can be any valid regular expression
          # (this one will match URLs like /api/post/7298 and /api/comment/528491)
          # - { path: ^/api/(post|comment)/\d+$, roles: ROLE_USER }
  
  </code></pre>
  <p>User.php:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace App\Entity;
  
  use App\Repository\UserRepository;
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Security\Core\User\UserInterface;
  use App\Entity\Trait\HasDateTime;
  use ApiPlatform\Core\Annotation\ApiResource;
  use Symfony\Component\Validator\Constraints as Assert;
  
  /**
   * @ApiResource
   * @ORM\Entity(repositoryClass=UserRepository::class)
   * @ORM\Table(name=&quot;`user`&quot;)
   * @ORM\HasLifecycleCallbacks
   */
  class User implements UserInterface
  {
      use HasDateTime;
      /**
       * @ORM\Id
       * @ORM\GeneratedValue
       * @ORM\Column(type=&quot;integer&quot;)
       */
      private $id;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=180, unique=true)
       */
      #[Assert\NotBlank]
      #[Assert\Email]
      private $email;
  
      /**
       * @ORM\Column(type=&quot;string&quot;, length=180, unique=true)
       */
      #[Assert\NotBlank]
      private $username;
  
      /**
       * @ORM\Column(type=&quot;json&quot;)
       */
      private $roles = [];
  
      /**
       * @var string The hashed password
       * @ORM\Column(type=&quot;string&quot;)
       */
      #[Assert\NotBlank]
      private $password;
  
      public function getId(): ?int
      {
          return $this-&gt;id;
      }
  
      public function getEmail(): string
      {
          return (string) $this-&gt;email;
      }
  
      public function setEmail(string $email): self
      {
          $this-&gt;email = $email;
  
          return $this;
      }
  
      /**
       * A visual identifier that represents this user.
       *
       * @see UserInterface
       */
      public function getUsername(): string
      {
          return (string) $this-&gt;username;
      }
  
      public function setUsername(string $username): self
      {
          $this-&gt;username = $username;
  
          return $this;
      }
  
      /**
       * @see UserInterface
       */
      public function getRoles(): array
      {
          $roles = $this-&gt;roles;
          // guarantee every user at least has ROLE_USER
          $roles[] = 'ROLE_USER';
  
          return array_unique($roles);
      }
  
      public function setRoles(array $roles): self
      {
          $this-&gt;roles = $roles;
  
          return $this;
      }
  
      /**
       * @see UserInterface
       */
      public function getPassword(): string
      {
          return (string) $this-&gt;password;
      }
  
      public function setPassword(string $password): self
      {
          $this-&gt;password = $password;
  
          return $this;
      }
  
      /**
       * Returning a salt is only needed, if you are not using a modern
       * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
       *
       * @see UserInterface
       */
      public function getSalt(): ?string
      {
          return null;
      }
  
      /**
       * @see UserInterface
       */
      public function eraseCredentials()
      {
          // If you store any temporary, sensitive data on the user, clear it here
          // $this-&gt;plainPassword = null;
      }
  }
  
  </code></pre>
  <p>tried to save data in the database each time it saved passwords as plaintext.</p>
  <p>also tried to remove the trait class thought it might conflict some how which seems strange(i know) (but i just gave it a try) it was not hashing passwords even after removing the trait. what am i doing wrong or missing here?
  thanks in advance</p>