这段代码是API找回密码控制器action的核心部分,讲解了怎么连接ad域、怎样通过cn找到员工,赋予员工随机的新密码实现找回密码(也可以是修改密码)的功能
var ldapUrl = "LDAP://" + adIP + "/OU=" + companyName + ",DC=" + adDomain + ",DC=" + adDomain2;
DirectoryEntry entry = new DirectoryEntry(ldapUrl, adUser, adPassword, AuthenticationTypes.Secure);
DirectoryEntry userEntry = null;
string newPassword = null;
try
{
DirectorySearcher deSearch = new DirectorySearcher(entry);
deSearch.Filter = "(&(objectClass=user)(cn=" + user.code + "))";
deSearch.SearchScope = SearchScope.Subtree;
SearchResult result = deSearch.FindOne();
if (result != null)
{
userEntry = result.GetDire