Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# LDAP
Hi,
 
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.
 
regards,
Krishnamoorthy S
Posted 13-Dec-12 0:59am
Comments
ryanb31 at 13-Dec-12 8:18am
   
You'll want to use the System.DirectoryServices namespace.

1 solution

Rate this: bad
good
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; 
 
directoryEntry.Close();
 
Also, Howto: (Almost) Everything In Active Directory via C#[^]
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 269
1 Peter Leow 205
2 OriginalGriff 200
3 _Amy 190
4 Andreas Gieriet 180
0 OriginalGriff 7,540
1 Sergey Alexandrovich Kryukov 6,412
2 Maciej Los 3,849
3 Peter Leow 3,653
4 CHill60 2,702


Advertise | Privacy | Mobile
Web02 | 2.8.140721.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