Webserver prompt password

I have a webserver and i want it to prompt for password whenever i access it. How do i do it?

I have a webserver

On the Arduino? That means you have some code. Where is it?

There are two common types of authentication. One is HTTP Basic Authentication handled by code in the web server and in the web browser: http://en.wikipedia.org/wiki/Basic_access_authentication.

The other is simply presenting an ordinary HTML form for login and using server-side scripting (such as CGI) to validate the password and set a cookie on the client's browser, which is how this Arduino forum software (and, indeed, most websites today) work.

Here’s the code. I have a RFID and Ethernet code which i got from online. I just changed abit here and there to work with my I/O. In addition, i want to display the card holder’s name when he/she taps on the rfid. I could do this on the serial monitor but i can’t display it on the Webpage.

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



byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

byte ip[] = { 192, 168, 123, 104 };                      // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
EthernetServer server(8080);  //server port
EthernetClient client;
String readString;

// The RFID module's TX pin needs to be connected to the Arduino.

#define rxPin 3

#define txPin 5

#define limitSwitch 6



// Create a software serial object for the connection to the RFID module

SoftwareSerial rfid = SoftwareSerial( rxPin, txPin );

// Set up outputs

#define Alarm 8

#define ledPin 9

// Specify how long the output should be held.

#define unlockSeconds 3

// The tag database consists of two parts. The first part is an array of

// tag values with each tag taking up 5 bytes. The second is a list of

// names with one name for each tag (ie: group of 5 bytes). You can expand

// or shrink this as you see fit. Tags 2 and 3 are only there for example.

char* allowedTags[] = {

"720040C977", // Tag 1

"720040C1D9", // Tag 2

"234H647HSF", // Tag 3

};

// List of names to associate with the matching tag IDs

char* tagName[] = {

"Faheem", // Tag 1

"Chicken", // Tag 2

"Marcus", // Tag 3

};

// Check the number of tags defined

int numberOfTags = sizeof(allowedTags)/sizeof(allowedTags[0]);

int incomingByte = 0; // To store incoming serial data



void setup() 
{
  pinMode(ledPin, OUTPUT);

  digitalWrite(ledPin, LOW);

  pinMode(Alarm, OUTPUT);

  
  pinMode(limitSwitch,INPUT);
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
  
  rfid.begin(9600); // Serial port for connection to RFID module

 Serial.println("RFID Reader Initialized");
 
    
    while (!Serial) 
    {
    ; // wait for serial port to connect. Needed for Leonardo only
    }
    
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  
}


void loop() 
{  
 
         
         byte i = 0;

byte val = 0;

byte checksum = 0;

byte bytesRead = 0;

byte tempByte = 0;

byte tagBytes[6]; // "Unique" tags are only 5 bytes but we need an extra byte for the checksum

char tagValue[10];

// Read from the RFID module. Because this connection uses SoftwareSerial

// there is no equivalent to the Serial.available() function, so at this

// point the program blocks while waiting for a value from the module

if(rfid.available() > 0) { //Dazu gebastelt

if((val = rfid.read()) == 2) { // Check for header

bytesRead = 0;

while (bytesRead < 12) { // Read 10 digit code + 2 digit checksum

if(rfid.available() > 0) {

val = rfid.read();

if (bytesRead < 10)

{

tagValue[bytesRead] = val;

}

// Check if this is a header or stop byte before the 10 digit reading is complete

if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02)) 
{

break; // Stop reading

}

// Ascii/Hex conversion:

if ((val >= '0') && (val <= '9')) 
{

val = val - '0';

}

else if ((val >= 'A') && (val <= 'F')) {

val = 10 + val - 'A';

}

// Every two hex-digits, add a byte to the code:

if (bytesRead & 1 == 1) {

// Make space for this hex-digit by shifting the previous digit 4 bits to the left

tagBytes[bytesRead >> 1] = (val | (tempByte << 4));

if (bytesRead >> 1 != 5) { // If we're at the checksum byte,

checksum ^= tagBytes[bytesRead >> 1]; // Calculate the checksum... (XOR)

};

} else {

tempByte = val; // Store the first hex digit first

};

bytesRead++;

} // Ready to read next digit

}

// Send the result to the host connected via USB

if (bytesRead == 12) { // 12 digit read is complete

tagValue[10] = '\0'; // Null-terminate the string

Serial.print("Tag read: ");

for (i=0; i<5; i++) {

// Add a leading 0 to pad out values below 16

if (tagBytes[i] < 16) {

Serial.print("0");

}

Serial.print(tagBytes[i], HEX);

}

Serial.println();

Serial.print("Checksum: ");

Serial.print(tagBytes[5], HEX);

Serial.println(tagBytes[5] == checksum ? " -- passed." : " -- error.");

// Show the raw tag value

Serial.print("VALUE: ");

Serial.println(tagValue);

// Search the tag database for this particular tag

int tagId = findTag( tagValue );

// Only fire the strike plate if this tag was found in the database

if( tagId > 0 )

{

Serial.print("Authorized tag ID ");

Serial.print(tagId);

Serial.print("Unlocking for ");

Serial.println(tagName[tagId - 1]); // Get the name for this tag from the database

unlock(); // Fire the strike plate to open the lock

} else {

Serial.println("Tag not authorized");


}

Serial.println(); // Blank separator line in output

}

bytesRead = 0;

}

}

 // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {   
      if (client.available()) {
        char c = client.read();
        int tagId = findTag( tagValue );
       
     
        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string
          readString += c;
          //Serial.print(c);
         }





         //if HTTP request has ended
         if (c == '\n') {        
           Serial.println(readString); //print to serial monitor for debuging
            
     
           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("<meta name='apple-mobile-web-app-capable' content='yes' />");
           client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
           client.println("<link rel='stylesheet' type='text/css' href='http://randomnerdtutorials.com/ethernetcss.css' />");
           client.println("<TITLE>My Home</TITLE>");
           client.println("</HEAD>");
           client.println("<BODY>");
           client.println("<H1>FYP: INTELLIGENT HOME</H1>");
           client.println("<body bgcolor=\"#A3A3A3\">");
           client.println("<hr />");
           client.println("
");  
           client.println("<hr />");
           client.println("
");
           client.println("
");
           client.println("
"); 
           client.print("<input type=submit value=UnlockDoor style=width:100px;height:45px onClick=location.href='/?on8'>");
           client.println("
");
           client.println("
");
           client.println("<hr />"); 
          
           
           client.println("Authorized tag ID:  ");
           client.print(tagId);
           client.println("
");
           client.println("
");
          
           client.println("
");     
           client.println("
");
         
           //client.println("<a href=\"/?button2on\"\"></a>");
           //client.println("<a href=\"/?button2off\"\"></a>
"); 
          
           client.println("
"); 
           client.println("</BODY>");
           client.println("</HTML>");
     
           delay(1);
           //stopping client
           client.stop();
           //controls the Arduino if you press the buttons
           if (readString.indexOf("?button1on") >0)
           { 
            unlock();
           
           }
           if (readString.indexOf("?button1off") >0)
           {
             
           }
          
         
            //clearing string for next read
            readString="";  
           
         }
       }
    }
}
}

void unlock() {

digitalWrite(ledPin, HIGH);


delay(unlockSeconds * 1000);


digitalWrite(ledPin, LOW);

}

void soundAlarm()
{
  digitalWrite(Alarm,HIGH);
  
  delay(5000);
  
  digitalWrite(Alarm,LOW);
}

/**

* Search for a specific tag in the database

*/

int findTag( char tagValue[10] ) {

for (int thisCard = 0; thisCard < numberOfTags; thisCard++) {

// Check if the tag value matches this row in the tag database

if(strcmp(tagValue, allowedTags[thisCard]) == 0)

{

// The row in the database starts at 0, so add 1 to the result so

// that the card ID starts from 1 instead (0 represents "no match")

return(thisCard + 1);

}

}

// If we don't find the tag return a tag ID of 0 to show there was no match

return(0);

}

I don't get it. If your Arduino is the web server, then the RFID card reader should be attached to the user's client PC somewhere else on the network, not to the Arduino. Or if you want to attach the RFID card reader to the Arduino, then then Arduino should act as a web client, not a web server.

Can you please explain better what this whole system is supposed to accomplish? It doesn't make sense to me right now.

The RFID is connected to the ethernet shield. But for now i'm not using the ethernet shield to monitor who enters or leaves the house. The rfid just runs in the main loop. Instead, i am controlling the doors from the ethernet shield. Eg.Unlock door.