验证用户名和密码

问题描述 投票:1回答: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");
  }
}
html c html5 arduino ethernet
1个回答
0
投票

看看this page的密码保护Arduino WebServer,我使用这个技巧

© www.soinside.com 2019 - 2024. All rights reserved.