How to check if a username/password combination is valid for FOS UserBundle

谁说胖子不能爱 提交于 2019-12-07 10:08:52

问题


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:


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());
}


来源:https://stackoverflow.com/questions/27180912/how-to-check-if-a-username-password-combination-is-valid-for-fos-userbundle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!