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

后端 未结 7 2275
挽巷
挽巷 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:09

    lockoutTime is a attribute so the easiest way is to use:

    (&(objectClass=user)(lockoutDuration=*))) 
    

    for the non-empty entries.

    Update:

    However, this value is also set when the password expires, password needs to change etc.

    So it needs to be filtered by:

    UserPrincipal userPrincipal = new UserPrincipal(context);
    bool isLocked = userPrincipal.IsAccountLockedOut();
    

    to get the cases where the user is locked out because they violated the password policy e.g incorrectly entered the password 5 times.

提交回复
热议问题