gpt4 book ai didi

python - 在 Python 中使用 LDAP 检测 Active Directory 用户帐户是否被锁定

转载 作者:IT老高 更新时间:2023-10-28 21:12:04 31 4
gpt4 key购买 nike

我正在使用 python 的 ldap 模块验证用户登录。当登录失败时,我得到一个 ldap.INVALID_CREDENTIALS 登录,但这可能是因为密码错误或帐户被锁定。帐户在第三次尝试后被锁定。

我想检测到帐户被锁定并将其报告给沮丧的用户,而不是相同的“无效登录”消息。

正在寻找我找到的解决方案:

  • AD 不使用 userAccountControl LOCKED 标志;
  • 应该使用 lockoutTime 属性

我应该用来查找锁定用户的 LDAP 查询是:

(&(objectClass=user)(lockoutTime>=1))

或针对特定用户:

(&(objectClass=user)(sAMAccountName=jabberwocky)(lockoutTime>=1))

但这不起作用,查询每次都没有返回结果。

最佳答案

lockoutTime 中的值为零表示它没有被锁定。所以,你应该试试这个。

(&(objectClass=user)(!lockoutTime=0)) 

实际上,上面的查询仍然不是 100% 正确的。如果您阅读 MSDN 的细则,Microsoft 建议您将 Lockout-Time 属性添加到 Lockout-Duration 属性,然后将其与当前时间进行比较。那是因为有一种叫做锁定持续时间的东西。一旦锁定持续时间过去,用户将自动解锁。 Lockout-Duration 中的零表示该帐户被永久锁定,直到管理员解锁为止。

查看 MSDN article

This attribute value is only reset when the account is logged onto successfully. This means that this value may be non zero, yet the account is not locked out. To accurately determine if the account is locked out, you must add the Lockout-Duration to this time and compare the result to the current time, accounting for local time zones and daylight savings time.

关于python - 在 Python 中使用 LDAP 检测 Active Directory 用户帐户是否被锁定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11795294/

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