docs: def authenticate(self,
                       username,
                       password,
                       attribute=None,
                       base_dn=None,
                       search_filter=None,
                       search_scope=SUBTREE):
          '''Attempts to bind a user to the LDAP server.
  
          Args:
              username (str): DN or the username to attempt to bind with.
              password (str): The password of the username.
              attribute (str): The LDAP attribute for the username.
              base_dn (str): The LDAP basedn to search on.
              search_filter (str): LDAP searchfilter to attempt the user
                  search with.
  
          Returns:
              bool: ``True`` if successful or ``False`` if the
                  credentials are invalid.
          '''
          # If the username is no valid DN we can bind with, we need to find
          # the user first.
          valid_dn = False
  
          try:
              parse_dn(username)
              valid_dn = True
          except LDAPInvalidDnError:
              pass
  
          if valid_dn is False:
              user_filter = '({0}={1})'.format(attribute, username)
              if search_filter is not None:
                  user_filter = '(&{0}{1})'.format(user_filter, search_filter)
  
              try:
                  self.connection.search(base_dn, user_filter, search_scope,
                                         attributes=[attribute])
                  response = self.connection.response
                  username = response[0]['dn']
              except (LDAPInvalidDnError, LDAPInvalidFilterError, IndexError):
                  return False
  
          try:
              conn = self.connect(username, password)
              conn.unbind()
              return True
          except LDAPBindError:
              return False