【发布时间】:2017-03-06 20:48:22
【问题描述】:
我的登录窗口使用 LDAP 来验证用户。但是,在验证时,它总是返回 false。
这是我从 CodeProject 获得的验证代码:
public bool fnValidateUser()
{
bool validation;
try
{
LdapConnection lcon = new LdapConnection
(new LdapDirectoryIdentifier((string)null, false, false));
NetworkCredential nc = new NetworkCredential(Environment.UserName,
txtPassword.SecurePassword, Environment.UserDomainName);
lcon.Credential = nc;
lcon.AuthType = AuthType.Negotiate;
// user has authenticated at this point,
// as the credentials were used to login to the dc.
lcon.Bind(nc);
validation = true;
}
catch (LdapException)
{
validation = false;
}
return validation;
}
txtPassword.SecurePassword 是密码框。当我输入密码/pin 并点击登录时,只要验证为假,它就会显示 MessageBox。
我做错了什么?
更新:异常表示“LDAP 服务器不可用”,在这一行lcon.Bind(nc);
【问题讨论】:
-
添加一个日志来捕获异常,你得到了什么异常?
-
@Dinesh 我刚刚添加了它
-
根据这个例外,您的 LDAP 服务器已关闭或根本没有连接。
标签: c# wpf validation ldap