Click here to Skip to main content
12,560,241 members (46,671 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# LDAP

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
Posted 13-Dec-12 0:59am
ryanb31 13-Dec-12 8:18am
You'll want to use the System.DirectoryServices namespace.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.161026.1 | Last Updated 13 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100