pagina web protetta da pasword - come si fa?

Ciao,
sto facendo i primi esperimenti con la scheda ethernet e mi piacerebbe accendere dei led, in remoto, dal web.
ho trovato questo sketch:

#include <Ethernet.h>
#include <SPI.h>
#include <WebServer.h> //libreria webduino
 
//variabili statiche per il mac address e lìip address
static byte mac_Add[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//cambiare l'ip in funzione della propria rete
static byte ip_Add[] = {
  192, 168, 1, 20 };
//creazione oggetto Webduino
WebServer webserver("", 80);
 
//Variabili booleane che memorizzano
//lo stato delle uscite collegate ai relè
boolean Rele1 = false;
boolean Rele2 = false;
boolean Rele3 = false;
 
//=============================================================================
//funzione pagina Start
void Start(WebServer &server, WebServer::ConnectionType type,
           char *url_param, bool param_complete)
{
  //restituisce al browser l'intestazione http 200 OK
  server.httpSuccess();
 
  //gestisco il tipo di richiesta HEAD
  if (type != WebServer::HEAD)
  {
    String s = "";
 
     if (param_complete == true)
    {
      s = url_param;
 
      if ( s == "R1=ON")
      {
        Rele1 = true;
        digitalWrite(2, HIGH);
      }
      else if ( s == "R1=OFF")
      {
        Rele1 = false;
        digitalWrite(2, LOW);
      }
 
      if ( s == "R2=ON")
      {
        Rele2 = true;
        digitalWrite(3, HIGH);
      }
      else if ( s == "R2=OFF")
      {
        Rele2 = false;
        digitalWrite(3, LOW);
      }
 
      if ( s == "R3=ON")
      {
        Rele3 = true;
        digitalWrite(4, HIGH);
      }
      else if ( s == "R3=OFF")
      {
        Rele3 = false;
        digitalWrite(4, LOW);
      }
    }
 
    //gestisco la pagina html in base allo stato delle uscite di Arduino
    P(htmlHead) =
    "<html>"
    "<head>"
    "<title>Arduino Scheda Rele</title>"
    "</head>"
    "<body>";
 
    server.printP(htmlHead);
 
    server.print("<table border=\"1\">");
    server.print("<tr><td>Stato Rele</td><td>Comandi</td></tr>");
 
    if(Rele1 == true)
      server.print("<tr><td style=\"color: red;\">RELE 1 ON</td><td>");
    else
      server.print("<tr><td style=\"color: black;\">RELE 1 OFF</td><td>");
 
    if(Rele1 == false)
      server.print("<input type=\"button\" value=\"clicca qui\"onclick=\"location.href='index.htm?R1=ON'\">");
    else
      server.print("<input type=\"button\" value=\"clicca qui\"onclick=\"location.href='index.htm?R1=OFF'\">");
 
    server.print("</td></tr>");
 
    if(Rele2 == true)
      server.print("<tr><td style=\"color: red;\">RELE 2 ON</td><td>");
    else
      server.print("<tr><td style=\"color: black;\">RELE 2 OFF</td><td>");
 
    if(Rele2 == false)
      server.print("<input type=\"button\" value=\"clicca qui\"onclick=\"location.href='index.htm?R2=ON'\">");
    else
      server.print("<input type=\"button\" value=\"clicca qui\"onclick=\"location.href='index.htm?R2=OFF'\">");
 
    server.print("</td></tr>");
 
    if(Rele3 == true)
      server.print("<tr><td style=\"color: red;\">RELE 3 ON</td><td>");
    else
      server.print("<tr><td style=\"color: black;\">RELE 3 OFF</td><td>");
 
    if(Rele3 == false)
      server.print("<input type=\"button\" value=\"clicca qui\"onclick=\"location.href='index.htm?R3=ON'\">");
    else
      server.print("<input type=\"button\" value=\"clicca qui\"onclick=\"location.href='index.htm?R3=OFF'\">");
 
    server.print("</td></tr>");
 
    server.print("</table></body></html>");
 
  }
}
//=============================================================================
 
void setup()
{
  //inizializzo l'ethernet shield con il mac e il address
  Ethernet.begin(mac_Add, ip_Add);
 
  //definisci l'azione di default che verrà eseguita quando l'utente
  //naviga nella root del sito
  webserver.setDefaultCommand(&Start);
  webserver.addCommand("index.htm", &Start);
 
  //avvia il web server
  webserver.begin();
 
  delay(100);
 
  //definisci i pin 2 3 4 in uscita
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
 
  //inizializza i le uscite
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
 
}
 
void loop()
{
  //elabora costantemente tutte le richieste provenienti dal browser
  webserver.processConnection();
}

Come faccio a proteggere la pagina con una password in modo tale da evitare che qualcuno mi cambi lo stato delle uscite?

Ho trovato questo sketch:

/* Web_Authentication.ino - Webduino Authentication example */

/* This example assumes that you're familiar with the basics
 * of the Ethernet library (particularly with setting MAC and
 * IP addresses) and with the basics of Webduino. If you
 * haven't had a look at the HelloWorld example you should
 * probably check it out first */

/* you can change the authentication realm by defining
 * WEBDUINO_AUTH_REALM before including WebServer.h */
#define WEBDUINO_AUTH_REALM "Weduino Authentication Example"

#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"

/* CHANGE THIS TO YOUR OWN UNIQUE VALUE.  The MAC number should be
 * different from any other devices on your network or you'll have
 * problems receiving packets. */
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

/* CHANGE THIS TO MATCH YOUR HOST NETWORK.  Most home networks are in
 * the 192.168.0.XXX or 192.168.1.XXX subrange.  Pick an address
 * that's not in use and isn't going to be automatically allocated by
 * DHCP from your router. */
static uint8_t ip[] = { 192, 168, 1, 210 };

/* This creates an instance of the webserver.  By specifying a prefix
 * of "", all pages will be at the root of the server. */
#define PREFIX ""
WebServer webserver(PREFIX, 80);

void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
  server.httpSuccess();
  if (type != WebServer::HEAD)
  {
    P(helloMsg) = "<h1>Hello, World!</h1><a href=\"private.html\">Private page</a>";
    server.printP(helloMsg);
  }
}

void privateCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
  /* if the user has requested this page using the following credentials
   * username = user
   * password = user
   * display a page saying "Hello User"
   *
   * the credentials have to be concatenated with a colon like
   * username:password
   * and encoded using Base64 - this should be done outside of your Arduino
   * to be easy on your resources
   *
   * in other words: "dXNlcjp1c2Vy" is the Base64 representation of "user:user"
   *
   * if you need to change the username/password dynamically please search
   * the web for a Base64 library */
  if (server.checkCredentials("dXNlcjp1c2Vy"))
  {
    server.httpSuccess();
    if (type != WebServer::HEAD)
    {
      P(helloMsg) = "<h1>Hello User</h1>";
      server.printP(helloMsg);
    }
  }
  /* if the user has requested this page using the following credentials
   * username = admin
   * password = admin
   * display a page saying "Hello Admin"
   *
   * in other words: "YWRtaW46YWRtaW4=" is the Base64 representation of "admin:admin" */
  else if (server.checkCredentials("YWRtaW46YWRtaW4="))
  {
    server.httpSuccess();
    if (type != WebServer::HEAD)
    {
      P(helloMsg) = "<h1>Hello Admin</h1>";
      server.printP(helloMsg);
    }
  }
  else
  {
    /* send a 401 error back causing the web browser to prompt the user for credentials */
    server.httpUnauthorized();
  }
}

void setup()
{
  Ethernet.begin(mac, ip);
  webserver.setDefaultCommand(&defaultCmd);
  webserver.addCommand("index.html", &defaultCmd);
  webserver.addCommand("private.html", &privateCmd);
  webserver.begin();
}

void loop()
{
  char buff[64];
  int len = 64;

  /* process incoming connections one at a time forever */
  webserver.processConnection(buff, &len);
}

Ma non riesco a “fonderli” assieme. Qualcuno mi sa aiutare?
Grazie

Ma si può fare?

La risposta la trovi su: gaffer.it
Ciao