Detect if an Active Directory user account is locked using LDAP in Python

后端 未结 7 2260
挽巷
挽巷 2020-12-14 08:53

I\'m validating user logins using python\'s ldap module. When the login fails, I get a ldap.INVALID_CREDENTIALS login, but this can be either because of a wrong password or

7条回答
  •  情歌与酒
    2020-12-14 09:14

    A value of zero in lockoutTime means it's not locked out. So, you should try this.

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

    Actually, the above query is still not 100% correct. If you read the fine print from MSDN, Microsoft is suggesting you to add the Lockout-Time attribute to the Lockout-Duration attribute and then compare it with the current time. That's because there is such a thing called lockout duration. Once the lockout duration passes, the user is unlocked automatically. Zero in Lockout-Duration means the account is locked forever until the administrator unlock it.

    See this 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.

提交回复
热议问题