Hello developers!
I am writing a small utility ( web-based
) that allows the user to change his password in Active Directory
and a few other goodies.
I use the following code for the .net 3.5
version:
public static string ChPassword(string domain, string container, string userName, string oldPassword, string newPassword) { PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, domain, container, "admin", "password"); UserPrincipal user = UserPrincipal.FindByIdentity(principalContext, userName); if (user == null) throw(new Exception("User Not Found In This Domain")); user.SetPassword(newPassword); user.Save(principalContext); return user.Name; }
Actually changing the password works, only after this change, both the old and new passwords work. That for me, in general, is strange.
Maybe someone worked with these libraries? Prompt, please, best-practices
for the decision of my problem. Thank.