.net - 如何在不将密码放入字符串的情况下检查 ActiveDirectory 上的用户/密码组合?

标签 .net active-directory directoryservices

我想检查 Windows 域上的用户/密码组合。现在我用下面的代码来做:

bool Login(String username, String password) {
    var principalContext = new PrincipalContext(ContextType.Domain);
    principalContext.ValidateCredentials(username, password);
}

虽然它有效,但让我烦恼的是我必须将密码放在 String 中。为了使用该 API;因为我正在使用 SecureString要将密码存储在其他任何地方,我真的很想使用某种方法来检查用户名/密码组合,而不必将密码作为托管 System.String 传递。 .

实现这一目标的最佳方法是什么?

最佳答案

您可以尝试的一种方法可能是:

通过使用 P/Invoke 调用 LoginUser 模拟用户,将密码作为 SecureString 传递 as described in MSDN .

使用模拟用户连接到 ActiveDirectory,无需传递用户名和密码:

AuthenticationTypes authenticationTypes = AuthenticationTypes.Secure;

using (var entry = new DirectoryEntry("LDAP://example.com", "", "", authenticationTypes))
{
    ...
}

我没有试过这个,但在我看来它应该有效。

关于.net - 如何在不将密码放入字符串的情况下检查 ActiveDirectory 上的用户/密码组合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5548235/

相关文章:

.net - 为什么不能通过 .NET 中的 COM 使用 .NET COM 库?

c# - 当组合框打开时,Silverlight Combobox 触发 KeyDown 事件

c# - 尝试将 Dictionary<string, object> 分配给字符串变量时出现错误

c# - 按字母顺序过滤 Active Directory 用户

vbscript - Active Directory VBS搜索脚本的第1行中的错误 'Expected end of statement'

powershell - 管理员组的 SID 不显示在成员帐户中

java - JNDI:命名服务与目录服务

objective-c - 苹果操作系统 X : Get current username and home directory for current user from Directory Services

.net - LDAP 查询返回组中的所有用户

java - 像IDM一样自动抓取下载链接?