C# 检查用户是否锁定在LDAP中?

C# 检查用户是否锁定在LDAP中?,c#,active-directory,C#,Active Directory,我需要验证LDAP中的用户帐户是否已锁定 我正在使用下面的代码 const int ADS_UF_LOCKOUT = 0x00000010; DirectoryEntry entry = new DirectoryEntry (_path, domainAndUsername, pwd); if (((int)entry.Properties["useraccountcontrol"].Value & ADS_UF_LOCKOUT) == 1) { return true; }

我需要验证LDAP中的用户帐户是否已锁定 我正在使用下面的代码

const int ADS_UF_LOCKOUT = 0x00000010;
DirectoryEntry entry = new DirectoryEntry (_path, domainAndUsername, pwd);
if (((int)entry.Properties["useraccountcontrol"].Value & ADS_UF_LOCKOUT) == 1)
{
    return true;
}
但是如果用户帐户被锁定,我会收到“登录失败:错误的用户名/密码”


请提供帮助。

如果要确定用户帐户是否已锁定,则不能使用正在检查的用户帐户信息来确定此事实-因为用户帐户已锁定,您将被拒绝访问

您不会被告知无法登录的原因是由于帐户被锁定,这将被视为过度信息披露


如果要确定不允许登录的原因是否是由于帐户被锁定,则需要一个已登录的帐户,该帐户可以检查帐户锁定状态,而不是通过失败的连接进行尝试。

您也可以使用属性锁定时间:如果用户未被锁定,则为0。(使用管理员凭据连接到AD)

DirectoryEntry\u de=newdirectoryEntry(\u path,domainAdministratorName,pwd);//获取用户作为目录项对象
对象largeInteger=\u de.Properties[“锁定时间”].Value;//它是一个大整数,所以我们需要用一种稍微复杂的方法来得到它的值
长高地=
(Int32)
largeInteger.GetType()
.InvokeMember(“HighPart”,BindingFlags.GetProperty,null,largeInteger,null);
长下部=
(Int32)
largeInteger.GetType()
.InvokeMember(“LowPart”,BindingFlags.GetProperty,null,largeInteger,null);

long result=(long)((uint)lowPart+((long)highPart)虽然我还没有验证它,但似乎可以获得有关故障的其他信息:
DirectoryEntry _de = new DirectoryEntry (_path, domainAdmininstratorName, pwd); // get user as directory entry object
object largeInteger = _de.Properties["lockoutTime"].Value; // it's a large integer so we need to get it's value by a little bit complex way
long highPart =
            (Int32)
                largeInteger.GetType()
                    .InvokeMember("HighPart", BindingFlags.GetProperty, null, largeInteger, null);
long lowPart =
            (Int32)
                largeInteger.GetType()
                    .InvokeMember("LowPart", BindingFlags.GetProperty, null, largeInteger, null);
long result = (long) ((uint) lowPart + (((long) highPart) << 32));
if (result == 0) 
{
   // account is not locked
}
else
{
 // account is locked
}