I am trying to validate user, I can't user FOSub bcz it's not compatible with Symfony 4, I am coding something mine. I pass username and password through ajax to service. Method which trying to login user :
public function login($username, $password) {
$user = $this->entityManager->getRepository("App:Users")
->findOneBy(array('username' => $username));
}
if(!$this->encoder->isPasswordValid($user->getPassword(), $password)) {
return new Response(
'Username or Password not valid.',
Response::HTTP_UNAUTHORIZED,
array('Content-type' => 'application/json')
);
}
}
When I call this method I have error :
Type error: Argument 1 passed to Symfony\Component\Security\Core\Encoder\UserPasswordEncoder::isPasswordValid() must implement interface Symfony\Component\Security\Core\User\UserInterface, string given, called in /src/Service/Login.php on line 60
Why it's telling me that I have to implement some service when in Symfony documentation there is
isPasswordValid(string $encoded, string $raw, string $salt), Checks a raw password against an encoded password.
I don't understand this...
UserPasswordEncoder::isPasswordValid
expects two arguments,UserInterface $user and string $plainPassword
. Not the$hash, $plainPassword
you're sending it – JimLisPasswordValid($user, $password)
and you are done, @JimL is right you are looking at interface instead of implementation – kunicmarko20