Page view counter

Change user password in active directory.

Last post 01-08-2009 6:45 PM by blfoleyus. 4 replies.

Sort Posts:

  • Change user password in active directory.

    12-17-2008, 1:43 AM
    • Loading...
    • Dyamanagowda
    • Joined on 12-17-2008, 6:24 AM
    • Posts 9
    • Points 5
    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); }
  • Re: Change user password in active directory.

    12-17-2008, 3:25 AM
    • Loading...
    • blfoleyus
    • Joined on 05-24-2007, 6:46 AM
    • Orlando, Florida, USA
    • Posts 191
    • Points 1,129

    Changing Passwords With Active Directory Can Sometimes be very Crying (painful).

    I have used this code many times in the past, note the ldap path..

    1    
    2                if (newpassword.Text.ToString() == checknewpassword.Text.ToString())
    3                {
    4    	      // Just fetch the user's XXXX\xxx login name
    5                    SPWeb webContext = SPControl.GetContextWeb(Context);
    6                    string strLoginName = webContext.CurrentUser.LoginName;
    7    
    8                    int iPosition = strLoginName.IndexOf("\\") + 1;
    9                    strLoginName = strLoginName.Substring(iPosition);
    10   
    11                   DirectoryEntry entry = new DirectoryEntry("LDAP://blfoley.local", strLoginName, oldpassword.Text.ToString(),AuthenticationTypes.Secure);
    12                   DirectorySearcher search = new DirectorySearcher(entry);
    13   
    14                   search.Filter = "(SAMAccountName=" + strLoginName + ")";
    15                   search.SearchScope = SearchScope.Subtree;
    16   
    17                   search.CacheResults = false;
    18   
    19                   SearchResultCollection results = search.FindAll();
    20   
    21                   if (results.Count > 0)
    22                   {
    23                       foreach (SearchResult result in results)
    24                       {
    25                           try
    26                           {
    27                               entry = result.GetDirectoryEntry();
    28                           }
    29                           catch (Exception error) 
    30   			{ 
    31   			    output.Text += "" + error.Message.ToString(); 
    32                           }
    33                       }
    34                       try
    35                       {
    36                           entry.Invoke("ChangePassword", new object[] { oldpassword.Text.ToString(), newpassword.Text.ToString() });
    37                           entry.CommitChanges();
    38                           output.Text += "Password is changed";
    39                       }
    40                       catch (Exception)
    41                       {
    42                           output.Text += " Password couldn't be changed due to restrictions<b>";
    43                       }
    44                   }
    45                   else
    46                   {
    47                       output.Text += "&lt;BR> User not found or bad password";
    48                   }
    49               }
    50               else
    51               {
    52                   output.Text += "&lt;BR>Passwords don't match";
    53               }
    
     
    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.
  • Re: Change user password in active directory.

    12-26-2008, 4:18 AM
    • Loading...
    • Dyamanagowda
    • Joined on 12-17-2008, 6:24 AM
    • Posts 9
    • Points 5
    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 .
  • Re: Change user password in active directory.

    01-08-2009, 4:38 AM
    • Loading...
    • Dyamanagowda
    • Joined on 12-17-2008, 6:24 AM
    • Posts 9
    • Points 5
    Can anybody help on this pls
  • Re: Change user password in active directory.

    01-08-2009, 6:45 PM
    • Loading...
    • blfoleyus
    • Joined on 05-24-2007, 6:46 AM
    • Orlando, Florida, USA
    • Posts 191
    • Points 1,129

    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?

    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.
Page 1 of 1 (5 items)