当我开始研究这个主题时,我发现一切都非常令人困惑,本教程是最好的入门教程之一,因为有很多首字母缩略词增加了难度。
https://hynek.me/articles/ldap-a-gentle-introduction/
我会向您推荐一个关于验证的类似问题,但不是专门针对凭据
因为有几个代码 sn-ps 与此类工作相关。
Validate a username and password against Active Directory?
我认为您要问的是身份验证功能
我认为发布我的整个代码只会让你感到困惑,所以我会解释它的结构并希望你能继续前进并给出一个 sn-p。
我做的方法很多,方法如下:
公共类 LdapAuthentication
使用方法 IsAuthenticated
其中方法被传递域、用户名和密码
然后我使用
目录条目
目录搜索器
查找和过滤 SAMAccountName
然后,这取决于您的应用程序以及您要查找的内容。
但其中大部分都在
System.DirectoryServices
try
{ //Bind to the native AdsObject to force authentication.
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
return false;
}
//Update the new path to the user in the directory.
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception("Error authenticating user. " + ex.Message);
}
这应该足以让您开始搜索并获得所需的内容。祝你好运!