How to check if a username/password combination is

2019-05-11 06:53发布

We are currently using Symfony 2 and FOS/UserBundle for user authentication.

I want to check if a given username/password combination is valid without logging in. This is because another person is currently logged in but for example needs to do a specific action which needs to be done by someone with a higher clearance.

Basically I want another user to do a different controller action besides the person that is currently logged.

If there's a better way of doing this please let me know

1条回答
在下西门庆
2楼-- · 2019-05-11 07:41

How can validate username and password from controller #696

public function validUser($username, $password){

    $user = new Users();    //entity

    $factory = $this->get('security.encoder_factory');
    $encoder = $factory->getEncoder($user);

    $bool = $encoder->isPasswordValid($user->getPassword(),$password,$user->getSalt());
}
查看更多
登录 后发表回答