Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 331
wnoveno Avatar asked Jan 09 '23 08:01

wnoveno


1 Answers

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());
}
like image 140
Paweł Kolanowski Avatar answered Apr 09 '23 06:04

Paweł Kolanowski