Undefined method ‘encodePassword’. – error in Apiplateform security encoder undefined

enter image description here

I have a problem in my symfony security api in the service PasswordService. It can’t find the encoder

I can’t guess what should I do.
This is my security.yaaml file:

enter image description here

This is my code:

<?php

namespace AppServices;
use SymfonyComponentSecurityCoreEncoderUserPasswordEncoderInterface;


class PasswordService
{
    /**
     * @var PasswordService
     */
    private $userPasswordEncoder;

    /**
     * @param UserPasswordEncoderInterface $userPasswordEncoder
     */
    public function __construct(UserPasswordEncoderInterface $userPasswordEncoder)
    {
        $this->userPasswordEncoder = $userPasswordEncoder;
    }

    /**
     * @param object $entity
     * @param string $password
     * @return string
     */
    
    public function encode(object $entity, string $password): string
    {
        return $this->userPasswordEncoder->encodePassword($entity, $password);
    }

    /**
     * @param string $password
     * @return int
     */
    public function formatRequirement(string $password)
    {
        return preg_match('#^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*W)#', $password);
    }

    /**
     * @param object $entity
     * @param string $password
     * @return bool
     */
    public function isValid(object $entity, string $password): bool
    {
        return $this->userPasswordEncoder->isPasswordValid($entity, $password);
    }
}

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *