code: def auth(username, password):
      '''
      Simple LDAP auth
      '''
      if not HAS_LDAP:
          log.error('LDAP authentication requires python-ldap module')
          return False
  
      bind = None
  
      # If bind credentials are configured, verify that we receive a valid bind
      if _config('binddn', mandatory=False) and _config('bindpw', mandatory=False):
          search_bind = _bind_for_search(anonymous=_config('anonymous', mandatory=False))
  
          # If username & password are not None, attempt to verify they are valid
          if search_bind and username and password:
              bind = _bind(username, password,
                           anonymous=_config('auth_by_group_membership_only', mandatory=False)
                           and _config('anonymous', mandatory=False))
      else:
          bind = _bind(username, password,
                       anonymous=_config('auth_by_group_membership_only', mandatory=False)
                       and _config('anonymous', mandatory=False))
  
      if bind:
          log.debug('LDAP authentication successful')
          return bind
  
      log.error('LDAP _bind authentication FAILED')
      return Falsf auth(username, password):
      '''
      Simple LDAP auth
      '''
      if not HAS_LDAP:
          log.error('LDAP authentication requires python-ldap module')
          return False
  
      bind = None
  
      # If bind credentials are configured, verify that we receive a valid bind
      if _config('binddn', mandatory=False) and _config('bindpw', mandatory=False):
          search_bind = _bind_for_search(anonymous=_config('anonymous', mandatory=False))
  
          # If username & password are not None, attempt to verify they are valid
          if search_bind and username and password:
              bind = _bind(username, password,
                           anonymous=_config('auth_by_group_membership_only', mandatory=False)
                           and _config('anonymous', mandatory=False))
      else:
          bind = _bind(username, password,
                       anonymous=_config('auth_by_group_membership_only', mandatory=False)
                       and _config('anonymous', mandatory=False))
  
      if bind:
          log.debug('LDAP authentication successful')
          return bind
  
      log.error('LDAP _bind authentication FAILED')
      return False
docs: Simple LDAP auth