【发布时间】:2011-02-12 06:15:33
【问题描述】:
我正在使用下面的代码对 Active Directory 中的用户进行身份验证,但密码是以明文形式发送的。如何对我的密码进行哈希处理,然后将其发送到 Active Directory?
DirectoryEntry entry = new DirectoryEntry(path, username, pwd);
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);
}
return true;
【问题讨论】:
-
这是个好问题。出于好奇,您使用的是什么 AuthenticationType?
-
你的AuthenticationType是什么意思,我用的是System.DirectoryServices;用于身份验证的名称空间和提到的代码