public function setPassword(Member $member, $password, $oldPassword = null)
    {
        $validationResult = ValidationResult::create(true);

        $this->extend('onBeforeSetPassword', $member, $password, $validationResult);

        if (!$member->GUID) {
            SS_Log::log(sprintf('Cannot update Member ID %s, GUID not set', $member->ID), SS_Log::WARN);
            $validationResult->error(_t('LDAPAuthenticator.NOUSER', 'Your account hasn\'t been setup properly, please contact an administrator.'));
            return $validationResult;
        }

        $userData = $this->getUserByGUID($member->GUID);
        if (empty($userData['distinguishedname'])) {
            $validationResult->error(_t('LDAPAuthenticator.NOUSER', 'Your account hasn\'t been setup properly, please contact an administrator.'));
            return $validationResult;
        }

        try {
            if (!empty($oldPassword)) {
                $this->gateway->changePassword($userData['distinguishedname'], $password, $oldPassword);
            } else if ($this->config()->password_history_workaround) {
                $this->passwordHistoryWorkaround($userData['distinguishedname'], $password);
            } else {
                $this->gateway->resetPassword($userData['distinguishedname'], $password);
            }
            $this->extend('onAfterSetPassword', $member, $password, $validationResult);
        } catch (Exception $e) {
            $validationResult->error($e->getMessage());
        }

        return $validationResult;
    }
public function setPassword(Member $member, $password, $oldPassword = null)
    {
        $validationResult = ValidationResult::create(true);

        $this->extend('onBeforeSetPassword', $member, $password, $validationResult);

        if (!$member->GUID) {
            SS_Log::log(sprintf('Cannot update Member ID %s, GUID not set', $member->ID), SS_Log::WARN);
            $validationResult->error(_t('LDAPAuthenticator.NOUSER', 'Your account hasn\'t been setup properly, please contact an administrator.'));
            return $validationResult;
        }

        $userData = $this->getUserByGUID($member->GUID);
        if (empty($userData['distinguishedname'])) {
            $validationResult->error(_t('LDAPAuthenticator.NOUSER', 'Your account hasn\'t been setup properly, please contact an administrator.'));
            return $validationResult;
        }

        try {
            if (!empty($oldPassword)) {
                $this->gateway->changePassword($userData['distinguishedname'], $password, $oldPassword);
            } else if ($this->config()->password_history_workaround) {
                $this->passwordHistoryWorkaround($userData['distinguishedname'], $password);
            } else {
                $this->gateway->resetPassword($userData['distinguishedname'], $password);
            }
            $this->extend('onAfterSetPassword', $member, $password, $validationResult);
        } catch (Exception $e) {
            $validationResult->error($e->getMessage());
        }

        return $validationResult;
    }
public function setPassword ( Member $ member , $ password , $ oldPassword = null ) { $ validationResult = ValidationResult :: create ( true ) ; $ this -> extend ( 'onBeforeSetPassword' , $ member , $ password , $ validationResult ) ; if ( ! $ member -> GUID ) { SS_Log :: log ( sprintf ( 'Cannot update Member ID %s, GUID not set' , $ member -> ID ) , SS_Log :: WARN ) ; $ validationResult -> error ( _t ( 'LDAPAuthenticator.NOUSER' , 'Your account hasn\'t been setup properly, please contact an administrator.' ) ) ; return $ validationResult ; } $ userData = $ this -> getUserByGUID ( $ member -> GUID ) ; if ( empty ( $ userData [ 'distinguishedname' ] ) ) { $ validationResult -> error ( _t ( 'LDAPAuthenticator.NOUSER' , 'Your account hasn\'t been setup properly, please contact an administrator.' ) ) ; return $ validationResult ; } try { if ( ! empty ( $ oldPassword ) ) { $ this -> gateway -> changePassword ( $ userData [ 'distinguishedname' ] , $ password , $ oldPassword ) ; } else if ( $ this -> config ( ) -> password_history_workaround ) { $ this -> passwordHistoryWorkaround ( $ userData [ 'distinguishedname' ] , $ password ) ; } else { $ this -> gateway -> resetPassword ( $ userData [ 'distinguishedname' ] , $ password ) ; } $ this -> extend ( 'onAfterSetPassword' , $ member , $ password , $ validationResult ) ; } catch ( Exception $ e ) { $ validationResult -> error ( $ e -> getMessage ( ) ) ; } return $ validationResult ; }
Change a members password on the AD. Works with ActiveDirectory compatible services that saves the
password in the `unicodePwd` attribute.

@todo Use the Zend\Ldap\Attribute::setPassword functionality to create a password in
an abstract way, so it works on other LDAP directories, not just Active Directory.

Ensure that the LDAP bind:ed user can change passwords and that the connection is secure.

@param Member $member
@param string $password
@param string|null $oldPassword Supply old password to perform a password change (as opposed to password reset)
@return ValidationResult
@throws Exception
Change a members password on the AD . Works with ActiveDirectory compatible services that saves the password in the unicodePwd attribute .