[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Change Password of Active Directory user using C#

Posted on 2011-02-15
6
Medium Priority
?
4,588 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 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

825 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