src/Classes/AdldapUsers.php
public function changePassword($username, $password, $oldPassword, $isGUID = false)
    {
        $this->adldap->utilities()->validateNotNull('Username', $username);
        $this->adldap->utilities()->validateNotNull('Password', $password);
        $this->adldap->utilities()->validateNotNull('Old Password', $oldPassword);

        $this->adldap->utilities()->validateLdapIsBound();

        if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
            $message = 'SSL must be configured on your webserver and enabled in the class to set passwords.';

            throw new AdldapException($message);
        }

        if (!$this->connection->isBatchSupported()) {
            $message = 'Missing function support [ldap_modify_batch] http://php.net/manual/en/function.ldap-modify-batch.php';

            throw new AdldapException($message);
        }

        $userDn = $this->dn($username, $isGUID);

        if ($userDn === false) {
            return false;
        }

        $modification = [
            [
                'attrib' => 'unicodePwd',
                'modtype' => LDAP_MODIFY_BATCH_REMOVE,
                'values' => [$this->encodePassword($oldPassword)],
            ],
            [
                'attrib' => 'unicodePwd',
                'modtype' => LDAP_MODIFY_BATCH_ADD,
                'values' => [$this->encodePassword($password)],
            ],
        ];

        $result = $this->connection->modifyBatch($userDn, $modification);

        if ($result === false) {
            $error = $this->connection->getExtendedError();

            if ($error) {
                $errorCode = $this->connection->getExtendedErrorCode();

                $msg = 'Error: '.$error;

                if ($errorCode == '0000052D') {
                    $msg = "Error: $errorCode. Your new password might not match the password policy.";

                    throw new PasswordPolicyException($msg);
                } elseif ($errorCode == '00000056') {
                    $msg = "Error: $errorCode. Your old password might be wrong.";

                    throw new WrongPasswordException($msg);
                }

                throw new AdldapException($msg);
            } else {
                return false;
            }
        }

        return true;
    }
public function changePassword($username, $password, $oldPassword, $isGUID = false)
    {
        $this->adldap->utilities()->validateNotNull('Username', $username);
        $this->adldap->utilities()->validateNotNull('Password', $password);
        $this->adldap->utilities()->validateNotNull('Old Password', $oldPassword);

        $this->adldap->utilities()->validateLdapIsBound();

        if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
            $message = 'SSL must be configured on your webserver and enabled in the class to set passwords.';

            throw new AdldapException($message);
        }

        if (!$this->connection->isBatchSupported()) {
            $message = 'Missing function support [ldap_modify_batch] http://php.net/manual/en/function.ldap-modify-batch.php';

            throw new AdldapException($message);
        }

        $userDn = $this->dn($username, $isGUID);

        if ($userDn === false) {
            return false;
        }

        $modification = [
            [
                'attrib' => 'unicodePwd',
                'modtype' => LDAP_MODIFY_BATCH_REMOVE,
                'values' => [$this->encodePassword($oldPassword)],
            ],
            [
                'attrib' => 'unicodePwd',
                'modtype' => LDAP_MODIFY_BATCH_ADD,
                'values' => [$this->encodePassword($password)],
            ],
        ];

        $result = $this->connection->modifyBatch($userDn, $modification);

        if ($result === false) {
            $error = $this->connection->getExtendedError();

            if ($error) {
                $errorCode = $this->connection->getExtendedErrorCode();

                $msg = 'Error: '.$error;

                if ($errorCode == '0000052D') {
                    $msg = "Error: $errorCode. Your new password might not match the password policy.";

                    throw new PasswordPolicyException($msg);
                } elseif ($errorCode == '00000056') {
                    $msg = "Error: $errorCode. Your old password might be wrong.";

                    throw new WrongPasswordException($msg);
                }

                throw new AdldapException($msg);
            } else {
                return false;
            }
        }

        return true;
    }
public function changePassword ( $ username , $ password , $ oldPassword , $ isGUID = false ) { $ this -> adldap -> utilities ( ) -> validateNotNull ( 'Username' , $ username ) ; $ this -> adldap -> utilities ( ) -> validateNotNull ( 'Password' , $ password ) ; $ this -> adldap -> utilities ( ) -> validateNotNull ( 'Old Password' , $ oldPassword ) ; $ this -> adldap -> utilities ( ) -> validateLdapIsBound ( ) ; if ( ! $ this -> adldap -> getUseSSL ( ) && ! $ this -> adldap -> getUseTLS ( ) ) { $ message = 'SSL must be configured on your webserver and enabled in the class to set passwords.' ; throw new AdldapException ( $ message ) ; } if ( ! $ this -> connection -> isBatchSupported ( ) ) { $ message = 'Missing function support [ldap_modify_batch] http://php.net/manual/en/function.ldap-modify-batch.php' ; throw new AdldapException ( $ message ) ; } $ userDn = $ this -> dn ( $ username , $ isGUID ) ; if ( $ userDn === false ) { return false ; } $ modification = [ [ 'attrib' => 'unicodePwd' , 'modtype' => LDAP_MODIFY_BATCH_REMOVE , 'values' => [ $ this -> encodePassword ( $ oldPassword ) ] , ] , [ 'attrib' => 'unicodePwd' , 'modtype' => LDAP_MODIFY_BATCH_ADD , 'values' => [ $ this -> encodePassword ( $ password ) ] , ] , ] ; $ result = $ this -> connection -> modifyBatch ( $ userDn , $ modification ) ; if ( $ result === false ) { $ error = $ this -> connection -> getExtendedError ( ) ; if ( $ error ) { $ errorCode = $ this -> connection -> getExtendedErrorCode ( ) ; $ msg = 'Error: ' . $ error ; if ( $ errorCode == '0000052D' ) { $ msg = "Error: $errorCode. Your new password might not match the password policy." ; throw new PasswordPolicyException ( $ msg ) ; } elseif ( $ errorCode == '00000056' ) { $ msg = "Error: $errorCode. Your old password might be wrong." ; throw new WrongPasswordException ( $ msg ) ; } throw new AdldapException ( $ msg ) ; } else { return false ; } } return true ; }
Change the password of a user - This must be performed over SSL
Requires PHP 5.4 >= 5.4.26, PHP 5.5 >= 5.5.10 or PHP 5.6 >= 5.6.0.

@param string $username    The username to modify
@param string $password    The new password
@param string $oldPassword The old password
@param bool   $isGUID      Is the username passed a GUID or a samAccountName

@return bool

@throws AdldapException
Change the password of a user - This must be performed over SSL Requires PHP 5 . 4 > = 5 . 4 . 26 PHP 5 . 5 > = 5 . 5 . 10 or PHP 5 . 6 > = 5 . 6 . 0 .