Solved

Change Password of Active Directory user using C#

Posted on 2011-02-15
6
3,396 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now