Click here to Skip to main content
Rate this: bad
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 1:59am
ryanb31 at 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
0 BillWoodruff 260
1 Afzaal Ahmad Zeeshan 252
2 OriginalGriff 251
3 Mathew Soji 234
4 Maciej Los 230
0 OriginalGriff 6,419
1 Sergey Alexandrovich Kryukov 6,008
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,070

Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 13 Jan 2013
Copyright © CodeProject, 1999-2014
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