Hi,
I've implemented the same solution but I'm still getting error. Below are my coding. Anything I've done wrongly? App + Web and the AD server is on Win 2k platform.
DirectoryEntry de = oDE = new DirectoryEntry(LDAPConnectionString, adminID, AdminPassword, AuthenticationTypes.Secure);
DirectorySearcher deSearch = new DirectorySearcher();
deSearch.SearchRoot = de;
deSearch.Filter = "(&(objectClass=user)(objectCategory=person)(samaccountname=" + UserID + "))";
deSearch.SearchScope = SearchScope.Subtree;
SearchResult searchResult = deSearch.FindOne();
IntPtr token = IntPtr.Zero;
bool result = LogonUser(adminID, Domain, AdminPassword, 3, 0, ref token);
if (!result)
{
int errCode = GetLastError();
string errMessage = String.Empty;
switch (errCode)
{
case 5:
errMessage = "Access Denied";
break;
case 1326:
errMessage = "Logon failure: unknown user name or bad password.";
break;
}
throw new Exception(String.Format("GetLastError() returned: {0}, \"{1}\"", errCode, errMessage));
}
else
{
WindowsIdentity wi = new WindowsIdentity((token));
WindowsImpersonationContext wic = wi.Impersonate();
// Reset user's password
UserEntry.Invoke("SetPassword", new object[] { resetPwd });
UserEntry.CommitChanges();
wic.Undo();
CloseHandle(token);
}
Thanks.