fos user bundle security validation

fos user bundle security validation

A login authentication would be handled by securitybundle in symfony.

But how about if you need to validate or authenticate username and password from controller?

Here is what you can do

        
        public function authenticatememberAction($user, $password)
        {
           $valid = false;

           $user_manager = $this->get('fos_user.user_manager');
           $factory = $this->get('security.encoder_factory');

           $user = $user_manager->findUserByUsername($user);//get the user first
           if (!empty($user)) {
              $encoder = $factory->getEncoder($user); //then the encoder
              $valid = ($encoder->isPasswordValid($user->getPassword(),$password,$user->getSalt())) ? true : false;
           }

           return new JsonResponse(['valid'=>$valid]);
        }

The above snippet will validate if the provided username password combination is correct or not.

Check if the variable is defined in symfony twig

{% javascript could not be added in symfony assetic

Fatal error: require(): Failed opening required Hydrator in mongodb

bundle does not contain any mapped documents/entities

the requested PHP extension mongo is missing from your system.

Symfony file upload SplFileInfo::get error

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*