asp.net - 事件目录认证

标签 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;

最佳答案

如果您使用 .NET 3.5,那么我强烈建议您改用 System.DirectoryServices.AccountManagement命名空间(阅读所有相关信息: Managing Directory Security Principals in the .NET Framework 3.5 )。

S.DS.AM 中,很多事情都变得容易多了- 像验证用户:

PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
ctx.ValidateCredentials("test", "test", ContextOptions.SecureSocketLayer);

安全地执行此操作的唯一方法是指定 ContextOptions.SecureSocketLayer强制使用 SSL 保护连接的选项。

如果您无法迁移到 .NET 3.5 和 S.DS.AM ,您需要查看 AuthenticationTypes 您可以在 fourth overloaded constructor 中定义的 DirectoryEntry :
DirectoryEntry entry = 
     new DirectoryEntry(path, username, pwd, 
                        AuthenticationTypes.SecureSocketsLayer);

恐怕没有其他方法可以做到这一点 - 我认为客户端没有任何方法可以像 Windwos Server/Active Directory 那样散列密码,并传入散列值。 ..

关于asp.net - 事件目录认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4976662/

相关文章:

asp.net - 在 ASP.NET 程序中是否有可以写入临时文件的位置?

c# - 如何用 RadWindow 替换警告消息框

javascript - ASP.net C# 中的弹出计算器

c# - 从具有纬度和经度的反向地理编码中获取城市名称

active-directory - 如何使用 LDAP 请求启用或禁用 AD 用户帐户?

c# - 以编程方式设置 Active Directory 密码时,如何要求更改密码?

JQuery 工具提示 : How to have 2 different styles?

azure - 如何在 Powershell 中向 Azure AAD 应用程序授予管理员同意?

python - 克服 Active Directory 的 1000 条记录限制

c# - 从公司身份验证获取 Azure 帐户 key