/**
  * {@inheritDoc}
  *
  * @return void
  */
 public function run(EntityInterface $user)
 {
     $user->setActivationKey(base64_encode($this->secureRandom->nextBytes(24)));
     $user->setPassword($this->passwordEncoder->encodePassword($user->getPassword(), User::SALT));
     $user->setRegistrationDate(new \DateTime());
     $this->entityManager->getRepository(User::class)->add($user);
     $this->entityManager->flush();
 }
예제 #2
0
 /**
  * Checks for a new password and rehashes if necessary
  *
  * @param User                     $entity
  * @param PasswordEncoderInterface $encoder
  * @param string                   $submittedPassword
  *
  * @return string
  */
 public function checkNewPassword(User $entity, PasswordEncoderInterface $encoder, $submittedPassword)
 {
     if (!empty($submittedPassword)) {
         //hash the clear password submitted via the form
         return $encoder->encodePassword($submittedPassword, $entity->getSalt());
     }
     return $entity->getPassword();
 }
예제 #3
0
 public function generatePassword(PasswordEncoderInterface $encoder, HasPassword $object)
 {
     $salt = '';
     if (true === $object instanceof HasSalt || true === $object instanceof UserInterface) {
         $salt = $object->getSalt();
     }
     return $encoder->encodePassword($object->getPlainPassword(), $salt);
 }
예제 #4
0
파일: User.php 프로젝트: saro0h/workshop
 /**
  * @param PasswordEncoderInterface $encoder
  */
 public function encodePassword(PasswordEncoderInterface $encoder)
 {
     if ($this->rawPassword) {
         $this->salt = sha1(uniqid(mt_rand()));
         $this->password = $encoder->encodePassword($this->rawPassword, $this->salt);
         $this->eraseCredentials();
     }
 }
예제 #5
0
파일: User.php 프로젝트: phecho/gitonomy
 /**
  * @inheritdoc
  */
 public function setPassword($raw, PasswordEncoderInterface $encoder = null)
 {
     $this->salt = md5(uniqid() . microtime());
     if (null === $encoder) {
         $this->password = $raw;
         return;
     }
     $this->password = $encoder->encodePassword($raw, $this->salt);
 }
예제 #6
0
 public function it_does_nothing_if_plain_password_is_empty($encoderFactory, PasswordEncoderInterface $encoder, UserInterface $user)
 {
     $user->getPlainPassword()->willReturn('');
     $user->getSalt()->willReturn('typicalSalt');
     $encoderFactory->getEncoder($user)->shouldNotBeCalled();
     $encoder->encodePassword('', 'typicalSalt')->shouldNotBeCalled();
     $user->setPassword(Argument::any())->shouldNotBeCalled();
     $user->eraseCredentials()->shouldNotBeCalled();
     $this->updatePassword($user);
 }
 /**
  * Attempt to authenticate the provided token using the provided user provider.
  * @param TokenInterface $token
  * @param UserProviderInterface $userProvider
  * @param string $providerKey
  * @return UsernamePasswordToken
  * @throws BadCredentialsException
  */
 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     if ($user = $userProvider->loadUserByUsername($token->getUsername())) {
         $userPassword = $user->getPassword();
         $tokenCredentials = $token->getCredentials();
         if ($userPassword == $this->initPassword && $user instanceof MutableUserInterface && $userProvider instanceof MutableUserProviderInterface) {
             // set both salt & password
             $user->setSalt(substr(md5(rand(1, 10000)), 0, 5));
             $user->setPassword($this->passwordEncoder->encodePassword($tokenCredentials, $user->getSalt()));
             // save the user
             $userProvider->saveUser($user);
             // return it
             return new UsernamePasswordToken($user, $user->getPassword(), $providerKey, $user->getRoles());
         } else {
             if ($this->passwordEncoder->isPasswordValid($userPassword, $tokenCredentials, $user->getSalt())) {
                 return new UsernamePasswordToken($user, $userPassword, $providerKey, $user->getRoles());
             }
         }
     }
     throw new BadCredentialsException('The presented password is invalid.');
 }
 /**
  * Encode a password
  *
  * @param string $password Password
  * @param string $salt     salt
  *
  * @return string password encrypted
  */
 public function encryptPassword($password, $salt = null)
 {
     return $this->passwordEncoder->encodePassword($password, $salt);
 }
예제 #9
0
 protected function getEncodedPassword(UserInterface $user, $password)
 {
     return !$this->encoder instanceof PasswordEncoderInterface ? $this->encoder->encodePassword($user, $password, $user->getSalt()) : $this->encoder->getEncoder($user)->encodePassword($password, $user->getSalt());
 }
예제 #10
0
 /**
  * Sets the password for a user.
  *
  * @param user   $user
  * @param string $password
  */
 private function doSetPassword(User $user, $password)
 {
     $user->setNonce(base_convert(sha1(uniqid(mt_rand(), true)), 16, 36));
     $user->setPassword($this->passwordEncoder->encodePassword($password, $user->getNonce()));
     $user->setSaltedPassword(true);
 }
예제 #11
0
 public function createNewAccount(PasswordEncoderInterface $encoder, ObjectManager $em, $email, $password, array $data = array())
 {
     //  set default values
     foreach ($data as $field => $val) {
         $method = 'set' . ucfirst($field);
         if (method_exists($this, $method)) {
             $this->{$method}($val);
         }
     }
     $password = $encoder->encodePassword($password, $this->getSalt());
     $this->setPassword($password);
     $this->setEmail($email);
     $this->setCreateAt(new \DateTime());
     $this->setLastActivity(new \DateTime());
     $this->setUpdateAt(new \DateTime());
     $this->setIsActive(true);
     $em->persist($this);
     $em->flush();
 }
예제 #12
0
 /**
  * @param  PasswordEncoderInterface $passwordencoder
  */
 public function updatePassword(PasswordEncoderInterface $passwordencoder)
 {
     $this->password = $passwordencoder->encodePassword($this->plainPassword, $this->getSalt());
 }
예제 #13
0
 public function processChangedPassword(PasswordEncoderInterface $encoder)
 {
     $this->generateSalt();
     $this->outputEncodedPassword = $encoder->encodePassword($this->password, $this->outputSalt);
 }
예제 #14
0
 /**
  * Sets the password for a user.
  *
  * @param user   $user
  * @param string $password
  */
 private function doSetPassword(User $user, $password)
 {
     $user->setNonce($this->generator->generateString(64));
     $user->setPassword($this->passwordEncoder->encodePassword($password, $user->getNonce()));
     $user->setSaltedPassword(true);
 }
예제 #15
0
파일: User.php 프로젝트: netagora/netagora
 public function encodePlainPassword(PasswordEncoderInterface $encoder)
 {
     $this->salt = $this->generateRandomSalt();
     $password = $encoder->encodePassword($this->plainPassword, $this->salt);
     $this->setPassword($password);
 }
예제 #16
0
파일: User.php 프로젝트: 3wil/GIFTploy
 public function encodePassword(PasswordEncoderInterface $encoder)
 {
     $this->password = $encoder->encodePassword($this->password, $this->salt);
 }