Trying to configure cotestatnt/esp-fs-webserver with username password

Hi Everybody,

I have quite some experience with "standard"-programming but no experiences with the deeper specialties of C++-coding.

I'm trying to configure the esp-fs-webserver from user cotestatnt to work with username and password. This is the GiPo with the library

I looked into the headerfile
https://github.com/cotestatnt/esp-fs-webserver/blob/main/src/esp-fs-webserver.h
and the cpp-file
https://github.com/cotestatnt/esp-fs-webserver/blob/main/src/esp-fs-webserver.cpp

But I have only a dark intuition what I might have to change to get access to the website only after entering a username and a password

In the cpp-file
there are line 72 and 73

// OTA update via webbrowser
    m_httpUpdater.setup(webserver);

which calls a setup-function
So I tried to followback where this comes from but are totally unsire if I'm on the right track
the header-file
has line 28

    using UpdateServerClass = ESP8266HTTPUpdateServer;
#elif defined(ESP32)

which mentions ESP8266HTTPUpdateServer

So I tried to find this ESP8266HTTPUpdateServer
and found it on my harddisk
here
C:\Users\dipl-\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\libraries\ESP8266HTTPUpdateServer\src\ESP8266HTTPUpdateServer.h

#ifndef __HTTP_UPDATE_SERVER_H
#define __HTTP_UPDATE_SERVER_H

#include <ESP8266WebServer.h>

namespace esp8266httpupdateserver {
using namespace esp8266webserver;

template <typename ServerType>
class ESP8266HTTPUpdateServerTemplate
{
  public:
    ESP8266HTTPUpdateServerTemplate(bool serial_debug=false);

    void setup(ESP8266WebServerTemplate<ServerType> *server)
    {
      setup(server, emptyString, emptyString);
    }

    void setup(ESP8266WebServerTemplate<ServerType> *server, const String& path)
    {
      setup(server, path, emptyString, emptyString);
    }

    void setup(ESP8266WebServerTemplate<ServerType> *server, const String& username, const String& password)
    {
      setup(server, "/update", username, password);
    }

    void setup(ESP8266WebServerTemplate<ServerType> *server, const String& path, const String& username, const String& password);

    void updateCredentials(const String& username, const String& password)
    {
      _username = username;
      _password = password;
    }

  protected:
    void _setUpdaterError();

  private:
    bool _serial_output;
    ESP8266WebServerTemplate<ServerType> *_server;
    String _username;
    String _password;
    bool _authenticated;
    String _updaterError;
};

};

#include "ESP8266HTTPUpdateServer-impl.h"


using ESP8266HTTPUpdateServer = esp8266httpupdateserver::ESP8266HTTPUpdateServerTemplate<WiFiServer>;

namespace BearSSL {
using ESP8266HTTPUpdateServerSecure = esp8266httpupdateserver::ESP8266HTTPUpdateServerTemplate<WiFiServerSecure>;
};

#endif

This header-file has a function setup that has parameters username and password

    void setup(ESP8266WebServerTemplate<ServerType> *server, const String& username, const String& password)
    {
      setup(server, "/update", username, password);
    }

So my assuming is there is a possability to configure it to use username and password.
I have no idea what a syntax like

    void setup(ESP8266WebServerTemplate<ServerType> *server)
File root = m_filesystem->open("/", "r");

especially the "->"

How would I build a version of the cotestatnt/esp-fs-webserver that has a locked door in front of all subsites

enter username and password

to get access to it?

best regards Stefan

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.