php - Password encoding symfony 3 -


i try make simple module in order register. anytime when submit form, error occur:

catchable fatal error: argument 1 passed symfony\component\security\core\encoder\userpasswordencoder::encodepassword() must implement interface symfony\component\security\core\user\userinterface, string given, called in ...

i read article not clear how implement userpasswordencoderinterface.

this action method:

public function registeraction(userpasswordencoderinterface $encoder, request $request){        $user = new user();         $form = $this->createformbuilder($user)                      ->add('username', texttype::class, array('label' => 'username', 'attr' => array('class' => 'form-control')))                      ->add('password', passwordtype::class, array('label' => 'password', 'attr' => array('class' => 'form-control')))                      ->add('register', submittype::class, array('label' => 'register', 'attr' => array('class' => 'btn btn-default')))                      ->getform();          $form->handlerequest($request);         if ($form->issubmitted() && $form->isvalid()){          $user->setroles(array('role_admin')); ///role_user          $encoded = $encoder->encodepassword($user->getusername(), $user-getpassword());          $user->setpassword($encoded);             $em = $this->getdoctrine()->getmanager();             $em->persist($user);             $em->flush();             return $this->redirecttoroute('login');         }         return $this->render('register.html.twig', ['form' => $form-createview()] );      } 

indeed

$encoded = $encoder->encodepassword($user, $user->getpassword());

thanks cerad!


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -