[英]LDAP Bind through .NET DirectoryEntry always succeeds
我正在使用用户的电子邮件地址作为键,在基于表单的C#登录方案中查找任意Windows帐户。 定位用户工作正常,我又得到了派生的UserPrincipalEx
。
但是,当我尝试使用“绑定”来验证登录时,它总是成功的:
// we can't use ValidateCredentials because it's too broken - multiple attempts each time,
// can't always negotiate properly, etc.
//if (!_principalContext.ValidateCredentials(userPrincipal.UserPrincipalName, password)) {
// return LoginValidationResults.ValidationFailed;
//}
try {
using (var directoryEntry = new DirectoryEntry("LDAP://" + _domain + "/" + _principalContext.Container,
userPrincipal.UserPrincipalName, password, AuthenticationTypes.FastBind)) {
var forceBind = directoryEntry.NativeObject;
Log.DebugFormat("Validation successful ({0}).", forceBind);
return LoginValidationResults.Valid;
}
}
catch (COMException ex) {
if (ex.ErrorCode != -2147023570) {
Log.DebugFormat("Validation exception: {0}", ex.ToString());
throw;
}
Log.Debug("Validation failed.");
return LoginValidationResults.ValidationFailed;
}
在某些情况下-我无法弄清楚它们的含义-不管我输入什么密码,该帐户始终可以成功绑定。
为什么会这样呢?
因此,我使用一些数据包捕获功能对此进行了调查,结果发现所有后续绑定均使用空白用户名。
果然,有问题的用户的UPN为空白(实际上为null
-未设置)。 在我们的情况下,这永远不会发生,但确实如此。 因为这是一个坏的用户案例,所以我只是检测到并抛出异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.