Ray*_*phy 7 asp.net active-directory
我正在使用下面的代码来验证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;
Run Code Online (Sandbox Code Playgroud)
如果您使用的是.NET 3.5,那么我强烈建议您切换到使用System.DirectoryServices.AccountManagement命名空间(阅读所有相关内容:在.NET Framework 3.5中管理目录安全主体).
很多东西都比较简单S.DS.AM- 比如验证用户:
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
ctx.ValidateCredentials("test", "test", ContextOptions.SecureSocketLayer);
Run Code Online (Sandbox Code Playgroud)
安全地执行此操作的唯一方法是指定ContextOptions.SecureSocketLayer使用SSL保护连接强制执行的选项.
如果你不能转移到.NET 3.5 S.DS.AM,你需要检查AuthenticationTypes你可以在第四个重载的构造函数中定义DirectoryEntry:
DirectoryEntry entry =
new DirectoryEntry(path, username, pwd,
AuthenticationTypes.SecureSocketsLayer);
Run Code Online (Sandbox Code Playgroud)
没有其他方法可以做到这一点,我担心 - 我认为在客户端没有任何方法可以像Windwos Server/Active Directory那样对密码进行哈希处理,并传递该哈希值. ..
| 归档时间: |
|
| 查看次数: |
2151 次 |
| 最近记录: |