question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Active Directory password change

See original GitHub issue

I’m trying to write a script which will allow users to change their own passwords on Active Directory. After a successful bind as the user with their ‘old’ password, I’m using:

client.modify(userDN, [
    new ldap.Change({
        operation: 'delete',
        modification: {
            unicodePwd: encodePassword(oldPassword)
        }
    }),
    new ldap.Change({
        operation: 'add',
        modification: {
            unicodePwd: encodePassword(newPassword)
        }
    })
], function(err) {
    if (err) {
        console.log(err.dn);
        console.log(err.code);
        console.log(err.name);
        console.log(err.message);
        client.unbind();
    }
    else {
        console.log('Password changed!');
    }
});

Where encodePassword is defined as

function encodePassword(password) {
    var newPassword = '';
    password = '"' + password + '"';
    for (var i = 0; i < password.length; i++) {
        newPassword += password[i] + "\000";
    }
    return new Buffer(newPassword).toString('base64');
}

which was taken from http://www.cs.bham.ac.uk/~smp/resources/ad-passwds/

The PHP script + ldapmodify works fine but the Node.js script gives a ConstraintViolationError with the message

0000216C: AtrErr: DSID-03190EB0, #1:
    0: 0000216C: DSID-03190EB0, problem 1005 (CONSTRAINT_ATT_TYPE), data 0, Att 9005a (unicodePwd)

The new password meets the constraints applied by the server (complexity etc) so I’m not sure what’s going wrong. As the password change can only be done over ldaps I can’t provide a Wireshark capture and I’m out of ideas. Any suggestions?

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:23 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
PhilWaldmanncommented, Oct 3, 2012

To change the password of an ActiveDirectory user you’ll need the following things:

  1. ldaps connection with valid certificate installed on the AD Server
  2. successful ldap bind
  3. proper rights to change the pw
  4. and utf16le encoded password in quotes

I’m using the following function to get the encoded password.

convertPassword: function(str){
    var output = '';
    str = '"' + str + '"';

    for(var i = 0; i < str.length; i++){
      output += String.fromCharCode( str.charCodeAt(i) & 0xFF,(str.charCodeAt(i) >>> 8) & 0xFF);
    }

    return output;
  } 
2reactions
ghostcommented, Nov 23, 2013
function encodePassword(password) {
    return new Buffer('"' + password + '"', 'utf16le').toString();
}

This works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Reset A User Password in Active Directory?
Right-click the domain user account you want to reset the password for in the right pane, and select Reset Password. Type a new...
Read more >
Change Windows Active Directory and LDS user password ...
This article describes how to change a Windows Active Directory and LDS user password through LDAP.
Read more >
How to Change or Update Your Active Directory Password
Connect to your company's network: In the office. Or, by connecting to a VPN when outside of the office. · Press Control +...
Read more >
How to Change User Passwords in Active Directory
Active Directory Users and Computers – A nice GUI that's been around since the dawn of AD is the most commonly used tool....
Read more >
Changing Your Active Directory Password
Changing Your Active Directory Password. Content Summary: Password Change: Android Update for District Mail, Contacts & Calendar.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found