Click here to Skip to main content
15,075,394 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

My issue is below,

I need to reset the password of a AD user on windows logon screen by checking some security questions.

I need to do it through LDAP using C#.

Hope your help to do so.

thanks in advance.

Krishnamoorthy S
ZurdoDev 13-Dec-12 8:18am
You'll want to use the System.DirectoryServices namespace.

1 solution

This code is untested but should point you in the right direction.

Youll need to provide credentials of a user in AD that has admin privileges to reset passwords. Will take username passed in from textbox to reset that users password.

string username = txtUsername.Text;

string adminUser = "AdminUserInAD";
string adminPass = "AdminUserPassInAD";
string ldapString = "LDAP://YourLDAPStringGoesHere";

DirectoryEntry de = new DirectoryEntry(ldapString , adminUser, adminPass, AuthenticationTypes.Secure);
DirectorySearcher deSearch = new DirectorySearcher(de) {SearchRoot = de, Filter = "(&(objectCategory=user)(cn=" + username + "))"};

var directoryEntry = deSearch.FindOne();

directoryEntry.Invoke("SetPassword", new object[] {"password"});
directoryEntry.Properties["LockOutTime"].Value = 0; 


Also, Howto: (Almost) Everything In Active Directory via C#[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900