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
Solved

Change Password of Active Directory user using C#

Posted on 2011-02-15
6
3,741 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
6 Comments
 
LVL 14

Expert Comment

by:Dhanasekaran Sengodan
ID: 34896432
0
 
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 500 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

789 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