• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

ESP32 Web Server using SPIFFS

Q&A Forum › Category: ESP32 › ESP32 Web Server using SPIFFS
0 Vote Up Vote Down
Javier Domínguez asked 6 years ago

In the example. ESP32 web server using SPIFFS, is there any way to put basic authentication?

Question Tags: ESP32 Web Server using SPIFFS basic authentication
2 Answers
0 Vote Up Vote Down
DK answered 6 years ago

Hi

There 3 ways

Use esp32 header files instead of esp8266

  • https://github.com/me-no-dev/ESPAsyncWebServer
  • https://randomnerdtutorials.com/esp32-web-server-spiffs-spi-flash-file-system/
  • https://github.com/gmag11/FSBrowserN
  • tttapa.github.io/ESP8266/Chap14%20-%20WebSocket.html

try this without spiffs

/////////////////////////////////////////////////////////////////////////////////////////////////

#include "ESPAsyncWebServer.h"
bool is_authentified()
{
Serial.println("Enter is_authentified");
if (server.hasHeader("Cookie"))
{
Serial.print("Found cookie: ");
String cookie = server.header("Cookie");
Serial.println(cookie);
if (cookie.indexOf("ESP=1") != -1)
{
Serial.println("Authentification Successful");
return true;
}
}
Serial.println("Authentification Failed");
return false;
}

void handleLogin()
{
if (server.hasArg("USER") && server.hasArg("PASS"))
{
if (server.arg("USER") == "1" && server.arg("PASS") == "1" )
{
server.sendHeader("Location", "/");
server.sendHeader("Cache-Control", "no-cache");
server.sendHeader("Set-Cookie", "ESP=1");
server.send(301);
Serial.println("Log in Successful");
logged_in = "1";
return;
}
//Incorrect login area
msg = "Wrong username/password..!!";
Serial.println("Log in Failed");
}
///
login form webpage
}

void handleRoot()
{
Serial.println("Enter handleRoot");
String header;
if (!is_authentified())
{
server.sendHeader("Location", "/login");
server.sendHeader("Cache-Control", "no-cache");
server.send(301);
return;
}
//////
your web page
}

server.on("/", handleRoot);
server.on("/login", handleLogin);

Hope it helps

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi Javier.
You can also follow this unit in the ESP32 course and try to adapt to your case: https://rntlab.com/module-4/making-your-esp32-web-server-password-protected/ using base 64 encoding
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.