Answer the question
In order to leave comments, you need to log in
What is the point of PasswordEncoderInterface when UserPasswordEncoderInterface exists and is used everywhere?
https://github.com/symfony/symfony/blob/5.x/src/Sy...
UserPasswordEncoderInterface
I don't understand what the first service is for. Always and everywhere used the second.
I dug into the sources, of course, but did not understand why.
For those who don't know
if ($encoder->isPasswordValid($user->toPassword()->password(), $typedPassword, $user->getSalt())) {
return;
}
}
if (false === $this->passwordEncoder->isPasswordValid($user, $request->get('password'))) {
return;
}
Answer the question
In order to leave comments, you need to log in
UserPasswordEncoderInterface
- just sugar when used in simple cases.
For example, you have an entity
class User implements UserInterface
{
public function __construct(string $username, string $password)
{
$this->username = $username;
$this->password = $password;
}
}
$password
, this is not plainPassword, but already hashed. UserPasswordEncoderInterface
requires an instance of this class?$user = new User($username, $this->encodePassword($plainPassword));
private EncoderFactoryInterface $encoderFactory;
private function encodePassword(string $plainPassword): string
{
$encoder = $this->encoderFactory->getEncoder(User::class);
return $encoder->encodePassword($plainPassword, null);
}
UserPasswordEncoderInterface
without having PasswordEncoderInterface
and EncoderFactoryInterface
, i.e. this is a higher level interface than PasswordEncoderInterface
public function getSalt()
{
return null;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question