簡體   English   中英

驗證用戶名和密碼

[英]Validating User name and password

我正在嘗試使用 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");
  }
}

查看此頁面以獲取受密碼保護的 Arduino WebServer,我使用此提示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM