?
Solved

Change Password of Active Directory user using C#

Posted on 2011-02-15
6
Medium Priority
?
4,257 Views
Last Modified: 2012-05-11
i am trying to ChangePassword of an active directory user using c# code

i picked up the code from msdn

however, i am getting an error when i run the code [see screenshot]

can someone please help me?


DirectoryEntry de = new DirectoryEntry("LDAP://arka.com", @"arka.com\prashanttesting", "curpwd", AuthenticationTypes.Secure);
        de.Invoke("ChangePassword", new object[] { "curpwd", "newpwd" });
        de.Close();

Open in new window

untitled.PNG
0
Comment
Question by:RakeshBhandari
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 10

Expert Comment

by:John Claes
ID: 34896606
RakeshBhandari :

The domain where you're testing upon is "arka.com"?
and the folowing user exists? "prashanttesting"
with the password? "Nbspl@123"

when copying code from any source you must first understand the code before starting a Build.
In this example you must check the domain/User and Password.

regards

poor beggar
0
 
LVL 2

Author Comment

by:RakeshBhandari
ID: 34903887
@poor_beggar
OFCOURSE i understand that code that i have taken from the other source and all the info (user, pwd, domain) is correct


@dhansmani
i do NOT want to setpassword as that will require me to have an a/c with admin privileges
i want to do it using ChangePassword method...but somehow its not working
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:Dhanasekaran Sengodan
ID: 34903997
refer this article in MSDN, its mightbe useful

http://msdn.microsoft.com/en-us/library/ms817839
0
 
LVL 15

Accepted Solution

by:
Russell_Venable earned 2000 total points
ID: 34912425
Your problem is IADsUser is not being reached. Something is wrong with A.) Input B.) Your settings are not configured properly.

Do you have a password policy in place? Do you have SSL enabled under your configuration? If SSL is enabled does the username match the SSL Certificate name? Active Directory enforces a restriction that any modification to the unicodePwd attribute must be made over an encrypted channel with a cipher strength of 128 bits.  So if SSL is not configured your password change will be rejected every time as a security precaution so joe-smo cannot see your clear-text password and then login using that account credentials.

Also this a better example of the above as you can see which of the fields they below too. It properly closes the connection and garbage collects on exit.
string ADPath = "LDAP://arka.com";
string ADUser = @"arka.com\prashanttesting";
string strOldPassword = "curpwd";
string strNewPassword = "newpwd";

using(DirectoryEntry oDE = new DirectoryEntry(ADPath, ADUser, ADPassword, AuthenticationTypes.Secure))
{
    try
    {
       // Change the password by exposing IADsUser ADSI interface
       oDE.Invoke("ChangePassword", new object[]{strOldPassword, strNewPassword});
    }  
    catch (Exception ex)
    {
       Debug.WriteLine("Error changing password. Reason: " + ex.Message);
    }
}

Open in new window



Reference:
LDAP Ports
Configuring Microsoft Active Directory for SSL Access
How to enable LDAP over SSL with a third-party certification authority
0
 
LVL 2

Author Closing Comment

by:RakeshBhandari
ID: 34923486
thank you!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question