Hi All, To change the password in active directory I have used the following code but i`m getting exception saying as Unknown error (0x80005000). Please some body help me in solving out this problem. I tried to run the "LADP://192.168.1.15” in run cmd but its
giving an error msg saying as --------------------------- Find People --------------------------- An error occurred while performing the search. Your computer, your Internet service provider, or the specified directory service may be disconnected. Check your
connections and try again. Operations Error --------------------------- OK --------------------------- Is that exception because of this error or it is something else suggest me how can I sole this . This is my code: ADPath = "LADP://192.168.1.15”; DirectoryEntry
oDE; oDE = new DirectoryEntry(ADPath, ADUser, ADPassword, AuthenticationTypes.Secure); try { // Change the password. oDE.Invoke("ChangePassword", new object[]{strOldPassword, strNewPassword}); } catch (Exception excep) { Debug.WriteLine("Error changing password.
Reason: " + excep.Message); }
Changing Passwords With Active Directory Can Sometimes be very [:'(] (painful).
I have used this code many times in the past, note the ldap path..
if (newpassword.Text.ToString() == checknewpassword.Text.ToString())
{
// Just fetch the user's XXXX\xxx login name
SPWeb webContext = SPControl.GetContextWeb(Context);
string strLoginName = webContext.CurrentUser.LoginName;
int iPosition = strLoginName.IndexOf("\\") + 1;
strLoginName = strLoginName.Substring(iPosition);
DirectoryEntry entry = new DirectoryEntry("LDAP://blfoley.local", strLoginName, oldpassword.Text.ToString(),AuthenticationTypes.Secure);
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + strLoginName + ")";
search.SearchScope = SearchScope.Subtree;
search.CacheResults = false;
SearchResultCollection results = search.FindAll();
if (results.Count > 0)
{
foreach (SearchResult result in results)
{
try
{
entry = result.GetDirectoryEntry();
}
catch (Exception error)
{
output.Text += "" + error.Message.ToString();
}
}
try
{
entry.Invoke("ChangePassword", new object[] { oldpassword.Text.ToString(), newpassword.Text.ToString() });
entry.CommitChanges();
output.Text += "Password is changed";
}
catch (Exception)
{
output.Text += " Password couldn't be changed due to restrictions<b>";
}
}
else
{
output.Text += "<BR> User not found or bad password";
}
}
else
{
output.Text += "<BR>Passwords don't match";
}
Brad Foley
Web Developer
http://www.blfoley.com --------------------------
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
Hi , I used the above code but it give exception once it return back from the invoke function . I mean once it reach line no 36 before coming to line 37 it goes to catch and gives error message saying Undisclosed exception .
Does the user that is executing the code have permission in active directory to change a password?
Is Impersonation turned on?
What were the specifics of the inner exception?
did the DirectoryEntry come back correctly?
Brad Foley
Web Developer
http://www.blfoley.com --------------------------
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
Dyamanagowda
Member
5 Points
9 Posts
Change user password in active directory.
Dec 17, 2008 05:43 AM|LINK
blfoleyus
Participant
1129 Points
192 Posts
Re: Change user password in active directory.
Dec 17, 2008 07:25 AM|LINK
Changing Passwords With Active Directory Can Sometimes be very [:'(] (painful).
I have used this code many times in the past, note the ldap path..
if (newpassword.Text.ToString() == checknewpassword.Text.ToString()) { // Just fetch the user's XXXX\xxx login name SPWeb webContext = SPControl.GetContextWeb(Context); string strLoginName = webContext.CurrentUser.LoginName; int iPosition = strLoginName.IndexOf("\\") + 1; strLoginName = strLoginName.Substring(iPosition); DirectoryEntry entry = new DirectoryEntry("LDAP://blfoley.local", strLoginName, oldpassword.Text.ToString(),AuthenticationTypes.Secure); DirectorySearcher search = new DirectorySearcher(entry); search.Filter = "(SAMAccountName=" + strLoginName + ")"; search.SearchScope = SearchScope.Subtree; search.CacheResults = false; SearchResultCollection results = search.FindAll(); if (results.Count > 0) { foreach (SearchResult result in results) { try { entry = result.GetDirectoryEntry(); } catch (Exception error) { output.Text += "" + error.Message.ToString(); } } try { entry.Invoke("ChangePassword", new object[] { oldpassword.Text.ToString(), newpassword.Text.ToString() }); entry.CommitChanges(); output.Text += "Password is changed"; } catch (Exception) { output.Text += " Password couldn't be changed due to restrictions<b>"; } } else { output.Text += "<BR> User not found or bad password"; } } else { output.Text += "<BR>Passwords don't match"; }Web Developer
http://www.blfoley.com
--------------------------
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
Dyamanagowda
Member
5 Points
9 Posts
Re: Change user password in active directory.
Dec 26, 2008 08:18 AM|LINK
Dyamanagowda
Member
5 Points
9 Posts
Re: Change user password in active directory.
Jan 08, 2009 08:38 AM|LINK
blfoleyus
Participant
1129 Points
192 Posts
Re: Change user password in active directory.
Jan 08, 2009 10:45 PM|LINK
A couple of things you need to check:
Does the user that is executing the code have permission in active directory to change a password?
Is Impersonation turned on?
What were the specifics of the inner exception?
did the DirectoryEntry come back correctly?
Web Developer
http://www.blfoley.com
--------------------------
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.