使用c#通过LDAP重置AD密码 [英] AD Password Reset through LDAP using c#
本文介绍了使用c#通过LDAP重置AD密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题如下,
我需要重置一个密码通过检查一些安全问题在Windows登录屏幕上添加用户。
我需要通过LDAP使用C#来完成。
希望你的帮助。
提前感谢。
问候,
Krishnamoorthy S
解决方案
此代码未经测试但应指向正确的方向。
您需要在AD中提供具有重置密码管理员权限的用户凭据。将从文本框传入的用户名重置该用户密码。
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 [] { 密码跨度>});
directoryEntry.Properties [ LockOutTime]。值= 0 跨度>;
directoryEntry.Close();
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
解决方案
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#[^]
这篇关于使用c#通过LDAP重置AD密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文