gpt4 book ai didi

c# - 无法验证用户名和密码

转载 作者:太空宇宙 更新时间:2023-11-03 23:17:37 25 4
gpt4 key购买 nike

我需要验证用户输入对于当前 session 窗口是否正确。因此我使用下面的代码:

private void LoginUser(string username, string password)
{
bool isCredentialValid = false;

using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
isCredentialValid = context.ValidateCredentials(username, password);
}
if (isCredentialValid)
{
//
}
else
{
//
}
}

我总是错误的问题ValidateCredentials结果。

Rq:我正在使用 .Net 4.5 框架

最佳答案

来自 MSDN http://msdn.microsoft.com/en-us/library/bb154889.aspx

The ValidateCredentials method binds to the server specified in the constructor. If the username and password parameters are null, the credentials specified in the constructor are validated. If no credential were specified in the constructor, and the username and password parameters are null, this method validates the default credentials for the current principal.

在 PrincipalContext 构造函数中,您还可以指定要检查的凭据。

 using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domain, 
container, ContextOptions.SimpleBind, username, password))
{
return pc.ValidateCredentials(domain + @"\" + username, password,
ContextOptions.SimpleBind);
}

试试这个。

关于c# - 无法验证用户名和密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36719775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com