2014-05-07 205 views
1

我正在尝试使用Arduino主板从Web服务器应用程序实现用户名和密码。在下面的代码中,我可以从用户获取用户名和密码。现在问题是如何比较结果比较。如果用户输入名称和密码,则必须检查并返回错误报告。验证用户名和密码

#include <SPI.h> 
#include <Ethernet.h> 
byte mac[] = { 
    0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 
IPAddress ip(192,168,1,128); 
EthernetServer server(80); 

void setup() { 
    Serial.begin(9600); 
    while (!Serial) { 
    ; // wait for serial port to connect. Needed for Leonardo only 
    } 
    Ethernet.begin(mac, ip); 
    server.begin(); 
    Serial.print("server is at "); 
    Serial.println(Ethernet.localIP()); 
} 


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(); 
     Serial.write(c); 
     if (c == '\n' && currentLineIsBlank) { 
      client.println("<!DOCTYPE html>"); 
      client.println("<html>"); 
      client.println("<body>"); 
      client.println("</form>"); 
      client.println("USER NAME:<input type='text' name='firstname'><br>"); 
      client.println("PASSWORD:<input type='password' name='pwd'><br>"); 
      client.println("<input type='submit'>"); 
      client.println("</form>"); 
      client.println("<body>"); 
      client.println("</html>"); 
      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 disonnected"); 
    } 
} 

回答

0

看一看this page用于保护Web服务器的Arduino密码,我用这个技巧