views:

63

answers:

1

I need to look for an example of a web application, preferably ASP.NET but any otherweb language will do, that lets Mac and Windows users change their AD password.

Any technique, application, or source code will be great.

P.S: our Macs are not connected to AD and we also have Windows users.

Thanks!

+1  A: 

The relevant library to look at is System.DirectoryServices. Something like this in your web app will do the trick:

// Elsewhere in your code:
using System.DirectoryServices;

// ...

string u = "userToFind"; // User to look for goes here.
DirectoryEntry de = GetDirectoryObject();
DirectorySearcher s = new DirectorySearcher();

s.SearchRoot = de;
s.Filter = "(&(objectClass=user)(SAMAccountName=" + u + "))";
s.SearchScope = SearchScope.Subtree;

SearchResult r = s.FindOne();

// Connect with user's credentials.
de = (r != null) ? new DirectoryEntry(
  r.Path, "user", "pwd", AuthenticationTypes.Secure) : null;

// ...

try {
   // Change the password.
   de.Invoke("ChangePassword", new object[]{strOldPassword, strNewPassword});
}
catch (Exception ex) {
   Debug.WriteLine("Error changing password. Reason: " + ex.Message);
}
John Feminella