/** * {@inheritDoc} */ public function load(ObjectManager $em) { $user = new User(); $user->setUsername('admin'); $encoder = $this->container->get('security.encoder_factory')->getEncoder($user); $user->setPassword($encoder->encodePassword('admin', $user->getSalt())); $em->persist($user); $em->flush(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('username'); $password = $input->getArgument('password'); $em = $this->getContainer()->get('doctrine')->getManager(); $user = new User(); $user->setUserName($username); $factory = $this->getContainer()->get('security.encoder_factory'); $encoder = $factory->getEncoder($user); $encodedPassword = $encoder->encodePassword($password, $user->getSalt()); $user->setPassword($encodedPassword); $em->persist($user); $em->flush(); $output->writeln(sprintf('Added %s user with password %s', $username, $password)); }
public function equals(User $user) { return $user->getUsername() == $this->getUsername(); }