Geeks With Blogs

Lance's TextBox » About Me » My Resume »Twitter

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 : , , , , , ,

Posted on Tuesday, November 28, 2006 3:19 PM Programming | Back to top


Comments on this post: How to change your active directory password

# re: How to change your active directory password
Requesting Gravatar...
oh, that's fantastic, I have been looking for this.. cheers for sharing..

Left by Linn on Apr 28, 2010 12:45 AM

# re: How to change your active directory password
Requesting Gravatar...
Thanks for posting a nice article
Left by Ganesan K on Sep 15, 2011 6:23 AM

Your comment:
 (will show your gravatar)


Copyright © Lance Robinson | Powered by: GeeksWithBlogs.net