验证用户名和密码

时间:2014-05-07 08:48:32

标签: html c html5 arduino ethernet

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

#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");
  }
}

1 个答案:

答案 0 :(得分:0)

请查看this page以获取受密码保护的Arduino WebServer,我使用此提示