Changes a users password

@param Model $user
@param $password
@throws ModelConsistencyValidationException Thrown if the new password was used previously within configured thresholds.
171147
public function changePassword(Model $user, $password)
    {
        //  Validate new password has not been previously used
        $numberOfPastPasswordsToCompareTo = $this->getSettings()->numberOfPreviousPasswords;

        if ($numberOfPastPasswordsToCompareTo) {
            $hashProvider = HashProvider::getProvider();

            $userPastPasswords = UserLog::find(
                new Equals("LogType", UserLog::USER_LOG_PASSWORD_CHANGED),
                new Equals("UserID", $user->UniqueIdentifier)
            );

            $userPastPasswords->addSort("DateCreated", false);
            $userPastPasswords->setRange(0, $numberOfPastPasswordsToCompareTo);

            foreach ($userPastPasswords as $log) {
                if ($hashProvider->compareHash($password, $log->Data)) {
                    $errors["Password"] = "The password you have entered has already been used. Please enter a new password.";

                    throw new ModelConsistencyValidationException($errors);
                }
            }
        }

        $user->setNewPassword($password);
        $user->save();

        // Only keep a fixed number of passwords. We keep the log entry but clear the 'data' - no point
        // keeping a trove of hashed passwords for someone to steal!
        $previousPasswordLogs = UserLog::find(
            new Equals("LogType", UserLog::USER_LOG_PASSWORD_CHANGED),
            new Equals("UserID", $user->UniqueIdentifier)
        );

        if ($previousPasswordLogs->count() >= $numberOfPastPasswordsToCompareTo) {
            $previousPasswordLogs->setRange($numberOfPastPasswordsToCompareTo - 1, 200);
            foreach ($previousPasswordLogs as $passwordToRemove)
            {
                $passwordToRemove->Data = '';
                $passwordToRemove->save();
            }
        }

        $log = new UserLog();
        $log->UserID = $user->UniqueIdentifier;
        $log->LogType = UserLog::USER_LOG_PASSWORD_CHANGED;
        $log->Data = $user->Password;
        $log->save();
        
    }
637951
def change_password(self, user, password):
        
        if not self.__contains__(user):
            raise UserNotExists
        self.new_users[user] = self._encrypt_password(password) + "\n"
771261
public function login(User $user, $password)
    {
        if ($user->isPasswordValid($password)) {
            $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
            $this->tokenStorage->setToken($token);
            $user->setLastLogin(new \DateTime());
            $this->save($user);

            return true;
        }

        return false;
    }
104629
public static function changeUser($user)
    {
        $currentUser = self::getCurrentUser();

        if ($currentUser != $user) {
            $user = posix_getpwnam($user);
            if ($user) {
                posix_setuid($user['uid']);
                posix_setgid($user['gid']);
            }
        }
    }
75637
def change_user_password(user, password):
    
    user.password = hash_password(password)
    _datastore.put(user)
    send_password_changed_notice(user)
    password_changed.send(current_app._get_current_object(),
                          user=user)
1212438
public function setPasswordAttribute($password)
    {
        if (!empty($password)) {
            $password = bcrypt($password);
            JWTUtilities::invalidateTokenByUserId($this->id);
            // When password is set user account must be confirmed. Confirming user
            // account here with confirm_code = null.
            // confirm_code = 'y' indicates cases where account is confirmed by user
            // using confirmation email.
            if (isset($this->attributes['confirm_code']) && $this->attributes['confirm_code'] !== 'y') {
                $this->attributes['confirm_code'] = null;
            }
        }

        $this->attributes['password'] = $password;
    }
1244385
public function login($user, $password)
    {
        /* @var $session \Mage_Customer_Model_Session */
        $session = Mage::getSingleton('customer/session');
        return $session->login($user, $password);
    }
977386
def change_password(self, new_password):
        
        self.set_password(new_password)
        self.save()
        password_changed.send(sender=self.__class__, user=self)
54241
public function setPassword(\Gems_User_User $user, $password)
    {
        $data['gup_id_user']         = $user->getUserLoginId();
        $data['gup_reset_key']       = null;
        $data['gup_reset_requested'] = null;
        $data['gup_reset_required']  = 0;
        if (null === $password) {
            // Passwords may be emptied.
            $data['gup_password'] = null;
        } elseif ($this->canSaveNewHash()) {
            $data['gup_password'] = $this->hashPassword($password);
        } else {
            $data['gup_password'] = $this->hashOldPassword($password);
        }
        $data['gup_last_pwd_change'] = new \Zend_Db_Expr('CURRENT_TIMESTAMP');

        $model = new \MUtil_Model_TableModel('gems__user_passwords');
        \Gems_Model::setChangeFieldsByPrefix($model, 'gup', $user->getUserId());

        $model->save($data);

        return $this;
    }
557978
public function changePassword($username, $password)
    {
        $user = $this->findUserByUsernameOrThrowException($username);
        $user->setPlainPassword($password);
        $this->userManager->updateUser($user);

        $event = new UserEvent($user, $this->getRequest());
        $this->dispatcher->dispatch(Events::USER_PASSWORD_CHANGED, $event);
    }
132592
final protected function _canChangePassword() {
         //validate that required indices exist
        if (!isset($this->_userProfile['username'])
            || !isset($this->_userProfile['password'])
            || !isset($this->_userProfile['fullname'])
            || !isset($this->_userProfile['passhist'])
        ) {
            throw new UserCredentialException('The username and password are not set', 1016);
        }
  
        //Verify if the password was changed today or server has been futuredated
        $currDateTimeObj = new \DateTime();
        
        //Password was changed today or in the future
        if ($currDateTimeObj <= $this->_userProfile['policyinfo']['password_last_changed_datetime']) {
            return false;
        } else {
            return true;
        }
    }
1039266
public function setPassword($password)
    {
        if (empty($password)) {
            $this->hashedPassword = null;
        } else {
            $this->hashedPassword = UsersManager::getPasswordHash($password);
        }
    }
608784
public function setPassword( core_kernel_classes_Resource $user, $password)
    {
        if(!is_string($password)){
			throw new core_kernel_users_Exception('The password must be of "string" type, got '.gettype($password));
		}
		
		$user->editPropertyValues(new core_kernel_classes_Property(GenerisRdf::PROPERTY_USER_PASSWORD),core_kernel_users_Service::getPasswordHash()->encrypt($password));
    }
1276532
public static function add($password, $user = null)
    {
        if (static::isUsed($password, $user) && !$user->allowUsedPassword) {
            throw new InvalidParamException('Password existed.');
        }
        if (static::judgePasswordHash($password)) {
            $passwordHistory = $user->create(static::class);
            $passwordHistory->{$passwordHistory->passwordHashAttribute} = $password;
        } else {
            $passwordHistory = $user->create(static::class, ['password' => $password]);
        }
        /* @var $passwordHistory static */
        return $passwordHistory->save();
    }
218
public function changePassword()
    {
        if ($this->validate()) {
            if (!($user = $this->getUser())) {
                return false;
            }
            if (!$user->applyForNewPassword()) {
                return false;
            }
            return $user->resetPassword($this->new_password, $user->getPasswordResetToken());
        }
        return false;
    }
710903
public function activateUser(User $user)
    {
        $user->setIsEnabled(true);
        $user->setIsMailValidated(true);
        $user->setResetPasswordHash(null);
        $user->setInitDate(new \DateTime());

        $this->objectManager->persist($user);
        $this->objectManager->flush();
    }
573801
public function withUserInfo($user, $password = null)
    {
        $userInfo = implode(':', [$user, $password]);

        return $this->_clone('userInfo', rtrim($userInfo, ':'));
    }