How to change your active directory password

Last year I posted the rules about how to remotely change your LDAP password. Its not very obvious because of the fact that the procedure depends on what server you're using (Active Directory, OpenLDAP, Novell, etc), and even then how your server is configured.

Here is how you would change your password using the LDAPS component of IP*Works!! SSL (note, an SSL connection is required in order to change your password remotely if you are an Active Directory user. Otherwise you can do this with the LDAP component in the regular IPWorks toolkit).

If you're not using IPWorks, the same rules apply, so adjust your code accordingly.  Here's a way to do it in PowerShell.

 

public void ChangePassword(string dn, string newpassword)
{
//Changing passwords depends on what directory server you're using:
//for Active Directory:

//*** You must have SSL connection in order for this to be allowed by AD!
//Also, this particular method of changing the password requires that you are already bound as Admin.
//Otherwise, you need to first delete the password providing the current value, and then

//re-add the password again with the new value.

ldap1.DN = dn;
ldap1.AttrCount = 1;
ldap1.AttrType[0] = "unicodePwd";
ldap1.AttrValueB[0] = System.Text.Encoding.Unicode.GetBytes("\"" + newpassword + "\"");
ldap1.AttrModOp[0] = LdapsAttrModOps.amoReplace;
ldap1.Modify();
if (ldap1.ResultCode != 0) { /* report/handle error here */ }

//for non-AD (ie Novell, OpenLdap, SunOne (iPlanet), etc): //No SSL is required /*
ldap1.DN = dn;
ldap1.AttrCount = 1;
ldap1.AttrType[0] = "userPassword";
ldap1.AttrValue[0] = newpassword;
ldap1.AttrModOp[0] = LdapsAttrModOps.amoReplace;
ldap1.Modify();
if (ldap1.ResultCode != 0) { /* report/handle error here */
}
*/
}

Technorati : , , , , , ,

Print | posted on Tuesday, November 28, 2006 3:19 PM

Feedback

# re: How to change your active directory password

Left by Linn at 4/28/2010 12:45 AM
Gravatar oh, that's fantastic, I have been looking for this.. cheers for sharing..

# re: How to change your active directory password

Left by Ganesan K at 9/15/2011 6:23 AM
Gravatar Thanks for posting a nice article

Your comment:





 
 

Copyright © Lance Robinson

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski