Arduino Web Password Login

have a good day project at school but i encountered a problem i can't add password to my home automation code can you help
asking for a password when entering a website

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
IPAddress ip(192, 168, 8, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

char header[500];
int bufferSize = 0;

void setup() {
  // Open serial communications and wait for port to open:

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  Serial.print("server is at ");

void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c =;
        if(bufferSize < 500) header[bufferSize++] = c;
        if (c == '\n' && currentLineIsBlank) {

          //parse headers
          //bWluaDp0ZXN0 = 'minh:test' (user:password) base64 encode
          // send a standard http response header
          if(strstr(header, "bWluaDp0ZXN0") != NULL) {
            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: text/html");
            client.println("Connection: close");  // the connection will be closed after completion of the response

            if(strstr(header, "GET / HTTP/1.1")) {
              client.println("<!DOCTYPE HTML>");
            } else {
              client.println("<!DOCTYPE HTML>");
              client.println("some other page");
          } else {
            // wrong user/pass
            client.println("HTTP/1.1 401 Unauthorized");
            //client.println("HTTP/1.1 401 Authorization Required");
            client.println("WWW-Authenticate: Basic realm=\"Secure\"");
            client.println("Content-Type: text/html");
            client.println("<html>Text to send if user hits Cancel button</html>"); // really need this for the popup!
          bufferSize = 0;
          StrClear(header, 500);
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
    // give the web browser time to receive the data
    // close the connection:
    Serial.println("client disconnected");

// sets every element of str to 0 (clears array)
void StrClear(char *str, char length)
    for (int i = 0; i < length; i++) {
        str[i] = 0;

I solved the issue, the subject may close

Hi Ulubey76,

Would you mind posting the version of code that works, because it might help someone out who has the same problem as you did! :slight_smile: