ESP32 S3 - Web Server Password

Securing your ESP32 S3 web server with a username and password is an essential step for any connected project where you want to restrict access. In this tutorial, you will learn how to set up an ESP32 S3 web server that requires users to log in with credentials before they can view the page content.

What you'll build:

  1. An ESP32 S3 web server that prompts visitors for a username and password
  2. A login challenge handled automatically by the web browser (no custom HTML login form needed)
  3. A protected web page that is only shown after successful authentication
  4. A reusable foundation for securing any ESP32 S3 web application
ESP32 S3 web server with username and password login

Hardware Preparation

1×ESP32 S3 WROOM N16R8
1×Alternatively, ESP32 S3 SuperMini Dev Module
1×Alternatively, ESP32 S3 Uno-form Board
1×Alternatively, ESP32 S3 Camera Board
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Recommended: Screw Terminal Expansion Board for ESP32 S3
1×Recommended: Breakout Expansion Board for ESP32 S3
1×Recommended: Power Splitter for ESP32 S3

Or you can buy the following kits:

1×DIYables ESP32 S3 Starter Kit (ESP32 S3 included)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of ESP32 S3 and Web Server

The ESP32 S3 is a powerful dual-core microcontroller with built-in Wi-Fi and Bluetooth, making it an excellent choice for web-connected projects. Its generous 16 MB of flash and 8 MB of PSRAM provide plenty of room for serving web content and handling multiple concurrent connections. If you are new to running a web server on the ESP32 S3, the tutorials below will give you the background you need.

Key Resources

ESP32 S3 Code - Web Server Username/Password

The following code sets up an ESP32 S3 web server that uses HTTP Basic Authentication to protect its content. When a browser first requests the page, the ESP32 S3 responds with an authentication challenge, and the browser automatically displays a login dialog — no custom HTML login form is required in your sketch.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-web-server-password */ /* * This ESP32-S3 code is created by esp32io.com * * This ESP32-S3 code is released in the public domain * * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-s3-web-server-password */ #include <DIYables_ESP32_WebServer.h> // WiFi credentials const char WIFI_SSID[] = "YOUR_WIFI_SSID"; const char WIFI_PASSWORD[] = "YOUR_WIFI_PASSWORD"; // Authentication credentials const char* www_username = "admin"; const char* www_password = "esp32"; // Create web server instance DIYables_ESP32_WebServer server; // Main page handler void handleRoot(WiFiClient& client, const String& method, const String& request, const QueryParams& params, const String& jsonData) { server.sendResponse(client, "<html><body><h1>Login Successful!</h1><p>You are now logged in.</p></body></html>"); } void setup() { Serial.begin(9600); delay(1000); // Configure the main route server.addRoute("/", handleRoot); // Start server with WiFi connection (handles connection automatically) server.begin(WIFI_SSID, WIFI_PASSWORD); // Enable basic authentication server.enableAuthentication(www_username, www_password, "Esp32"); Serial.print("IP Address: "); Serial.println(WiFi.localIP()); Serial.println("Server ready with authentication enabled"); Serial.print("Username: "); Serial.println(www_username); Serial.print("Password: "); Serial.println(www_password); } void loop() { // Handle all client requests (including authentication) server.handleClient(); }

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Connect the ESP32 S3 board to your PC via a USB Type-C cable.
  3. Open Arduino IDE on your PC.
  4. Select the right ESP32 S3 board (e.g. ESP32S3 Dev Module) and the correct COM port.
  5. Open the Library Manager by clicking on the Library Manager icon on the left navigation bar of Arduino IDE.
  6. Search "DIYables ESP32 WebServer", then find the Web Server library created by DIYables.
  7. Click Install button to install the Web Server library.
  • Search for DIYables ESP32 WebServer created by DIYables.io and click the Install button.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Library Manager
Type:
All
Topic:
All
DIYables ESP32 WebServer by DIYables.io
DIYables ESP32 WebServer library designed for ESP32 boards. It includes multi-page web server capabilities and WebSocket support for real-time communication, perfect for IoT projects and DIYables ESP32 boards. More info
1.0.1
INSTALL
Newbiely.ino
···
1 void setup() {
Output
Serial Monitor
Ln 1, Col 1
ESP32S3 Dev Module on COM15
1
  1. Copy the above code and open with Arduino IDE.
  2. Change the Wi-Fi information (SSID and password) in the code to match your network.
  3. Click Upload button on Arduino IDE to upload the code to the ESP32 S3.
  4. Open the Serial Monitor.
  5. Check out the result on Serial Monitor.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
Connecting to WiFi... Connected to WiFi ESP32 S3 Web Server's IP address: 192.168.0.3
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2
  1. You will see an IP address on the Serial Monitor, for example: 192.168.0.3.
  2. Type that IP address into the address bar of a web browser on your smartphone or PC.
  3. Please note that you need to replace 192.168.0.3 with the actual IP address shown on your Serial Monitor.
  4. You will see a login dialog prompting you to enter a username and password.
ESP32 S3 Web page password
  1. Enter the username and password defined in the code — by default: admin as the username and esp32 as the password.
  2. If you enter the correct credentials, the protected web content will be displayed.
ESP32 S3 Web page login
  1. Pro Tip: Once authenticated, your browser saves the credentials and automatically includes them in subsequent requests, so you will not be prompted again until you clear the browser session or restart the ESP32 S3.

※ NOTE THAT:

  • You can change the web username and password in the code by updating the values of the two variables: www_username and www_password.
  • You can extend this code to include your own HTML, CSS, and JavaScript content for the protected web page.
  • The login form is generated entirely by the web browser — there is no HTML login form in the ESP32 S3 sketch itself.

Advanced Knowledge

This section explains how the username and password system works at the HTTP protocol level, without any HTML login form in the ESP32 S3 code.

  • Initially, when you enter the IP address of the ESP32 S3 into a web browser, the browser sends an HTTP request to the board without any username or password credentials.
  • Upon receiving this request, the ESP32 S3 code checks whether credentials are included. If they are absent, the board does not return the page content. Instead, it responds with an HTTP message containing headers that instruct the browser to prompt the user for their username and password. Notably, this response contains no HTML code for a login form.
  • Upon receiving this response, the web browser parses the HTTP headers, recognises the authentication challenge, and dynamically generates a login dialog allowing the user to enter their credentials.
  • The user enters their username and password into the browser's login dialog.
  • The web browser includes the entered credentials within an HTTP request and sends it to the ESP32 S3.
  • The ESP32 S3 verifies the credentials. If they are correct, it returns the requested page content. If they are incorrect, it repeats the challenge, prompting the user to try again.
  • Once the user authenticates successfully for the first time, subsequent requests from the same browser session do not require re-entry of credentials, because the browser automatically includes the saved credentials in every following request.

Applications

Password-protecting a web server is useful in a wide range of real-world ESP32 S3 projects where unauthorised access could cause problems or expose sensitive data.

  1. Home Automation Dashboard: Restrict control of lights, fans, and appliances to authorised household members only.
  2. Remote Sensor Monitoring: Protect live temperature, humidity, or air-quality readings so only approved users can view them.
  3. Industrial Control Panel: Prevent unauthorised personnel from adjusting machine parameters via the web interface.
  4. IoT Device Configuration: Secure the settings page of a deployed ESP32 S3 device so only administrators can change Wi-Fi credentials or thresholds.
  5. Security Camera Interface: Guard access to a motion-triggered snapshot or video feed hosted on the ESP32 S3.

Video Tutorial

Watch the step-by-step video walkthrough for this ESP32 S3 project below.

Challenges

Now that your ESP32 S3 web server is secured with a password, try extending it with the following challenges.

  1. Beginner: Change the default username and password in the code to a custom pair of your choice, then verify that the old credentials no longer grant access.
  2. Intermediate: Add a second protected page at a different URL path (e.g. /status) that displays live sensor readings and also requires authentication.
  3. Advanced: Implement a logout mechanism that clears the browser's cached credentials by returning a 401 response when the user visits a /logout URL, forcing them to re-authenticate on their next visit.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!