How to implement remember me programatically in symfony2?

authentication, php, remember-me, symfony

Solution

Try to use RememberMeToken

$key = $this->getParameter('secret'); // your security key from parameters.yml

$token = new RememberMeToken($user, 'main', $key); 
$this->get('security.context')->setToken($token);

Problem

I have implemented a login function programmatically. This code is following: ``` $token = new UsernamePasswordToken($user, $user->getPassword(), 'main', $user->getRoles()); $this->get('security.context')->setToken($token); $event = new InteractiveLoginEvent($this->getRequest(),$token); $this->get('event_dispatcher')->dispatch('security.interactive_login', $event); ``` After this, how do I implement remember me ? (I know how to use form, but I want to implement remember me programmatically. ) please help...

Original source

Related problems