Juntar códigos

Boas, eu estou a tentar juntar dois códigos, no entanto não estou a ter sucesso, alguém me pode dar uma ajuda por favor??

Código 1

https://www.robocore.net/upload/RoboCore_Remote_AutomationV1_1.ino

Código 2

http://aquatictechtank.net/viewtopic.php?f=37&t=185&p=530#p530

Código feito

#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( 172, 16, 0, 10);
byte gateway[] = { 172, 16, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet masc
String readString;

int pin = 9; 
boolean ligado = true;

// 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 userPass[200];
//char header[500];
String header;
//int bufferSize = 0;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  pinMode(pin, OUTPUT); //pin selected to control
  //enable serial data print
  Serial.begin(9600);
  Serial.println("RoboCore Remote Automation V1.1"); // so I can keep track of what is loaded
}


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 = client.read();
        header += c;
        Serial.write(c);
  
        if (c == '\n' && currentLineIsBlank) {

          //parse headers
          //bWluaDp0ZXN0 = 'minh:test' (user:password) base64 encode
          String auth = "";
          //parse out user pass from client
          if(int startOfAuth = header.indexOf("Authorization: Basic")) {
            
            int i = startOfAuth+21;
            
            while(header.charAt(i) != '\n') {
              auth += header.charAt(i);
              i++;
            }
          }
          //if HTTP request has ended
        if (c == '\n') {

          ///////////////////// control arduino pin
          Serial.println(readString); //print to serial monitor for debuging
          if(readString.indexOf("?ligar") >0)//checks for on
          {
            digitalWrite(pin, HIGH);    // set pin 4 high
            Serial.println("On");
            ligado = false;
          }
          else{
            if(readString.indexOf("?desligar") >0)//checks for off
            {
              digitalWrite(pin, LOW);    // set pin 4 low
              Serial.println("Off");
              ligado = true;
            }
          }
          //clearing string for next read
          readString="";
          //get rid of any whitespaces
          auth.trim();
          
          Serial.print(auth);

          // send a standard http response header
          if(auth.compareTo("bWluaDp0ZXN0") != 0) {
            Serial.println("authenticate");
            client.println("HTTP/1.0 401 Authorization Required");
            client.println("WWW-Authenticate: Basic realm=\"Secure\"");
            client.println("Content-Type: text/html");
            client.println();
            client.println("<html>Text to send if user hits Cancel button</html>"); // really need this for the popup!
          } else {
           
            client.println("Connection: close");  // the connection will be closed after completion of the response
            //client.println("Refresh: 5");  // refresh the page automatically every 5 sec
            client.println();
             client.println("HTTP/1.1 200 OK"); //send new page
          client.println("Content-Type: text/html");
          client.println();

          client.println("<html>");
          client.println("<head>");
          client.println("<title>RoboCore - Remote Automation</title>");
          client.println("<meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>");
          client.println("<link rel='stylesheet' type='text/css' href='http://www.robocore.net/upload/projetos/RemoteAutomationV1.0.css' />");
          client.println("<script type='text/javascript' src='http://www.robocore.net/upload/projetos/RemoteAutomationV1.0.js'></script>");
          client.println("</head>");
          client.println("<body>");
          client.println("<div id='wrapper'>RoboCore Remote Automation V1.1");
          client.print("<div id='rele'></div><div id='estado' style='visibility: hidden;'>");
          client.print(ligado);
          client.println("</div>");
          client.println("<div id='botao'></div>");
          client.println("</div>");
          client.println("<script>AlteraEstadoRele()</script>");
          client.println("</body>");
          client.println("</head>");

          delay(1);
          //stopping client
          client.stop();
            break;
          }
        }
        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
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}
}

Obs:

IP do arduino: 172.16.0.10
Gateway: 172.16.0.1
Masc: 255.255.255.0
Mac Adress: 0x90, 0xA2, 0xDA, 0x00, 0x9B, 0x36

Agradeço a ajuda

Nao estas a ter sucesso em que parte?

Na união do sistema de login ao código de controlo remoto.