Solved

Change Password of Active Directory user using C#

Posted on 2011-02-15
6
4,041 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
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…

687 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