FosUserBundleでのログインチェック処理

必要になったので

 
public function loginAction($username, $password)
{
    $user_manager = $this->get('fos_user.user_manager');
    $factory = $this->get('security.encoder_factory');
 
    $user = $user_manager->loadUserByUsername($username);
 
    $encoder = $factory->getEncoder($user);
 
    $bool = ($encoder->isPasswordValid($user->getPassword(),$password,$user->getSalt())) ? "true" : "false";
 
    return array('name' => $bool);
}