code: def validate_ldap(self):
          'Validate the username/password data against ldap directory'
          ldap_mgr = current_app.ldap_login_manager
          username = self.username.data
          password = self.password.data
          try:
              userdata = ldap_mgr.ldap_login(username, password)
          except ldap.INVALID_CREDENTIALS:
              flash("Invalid LDAP credentials", 'danger')
              return False
          except ldap.LDAPError as err:
              if isinstance(err.message, dict):
                  message = err.message.get('desc', str(err))
              else:
                  message = str(err.message)
              flash(message, 'danger')
              return False
  
          if userdata is None:
              flash("Invalid LDAP credentials", 'danger')
              return False
  
          self.user = ldap_mgr._save_user(username, userdata)
          return Truf validate_ldap(self):
          'Validate the username/password data against ldap directory'
          ldap_mgr = current_app.ldap_login_manager
          username = self.username.data
          password = self.password.data
          try:
              userdata = ldap_mgr.ldap_login(username, password)
          except ldap.INVALID_CREDENTIALS:
              flash("Invalid LDAP credentials", 'danger')
              return False
          except ldap.LDAPError as err:
              if isinstance(err.message, dict):
                  message = err.message.get('desc', str(err))
              else:
                  message = str(err.message)
              flash(message, 'danger')
              return False
  
          if userdata is None:
              flash("Invalid LDAP credentials", 'danger')
              return False
  
          self.user = ldap_mgr._save_user(username, userdata)
          return True
docs: Validate the username/password data against ldap directory