Ich glaub ja:
Ersetzen tust Du bitte nur die Funktion handleNotAuthorized().Code:void handleNotAuthorized() { String readString = ""; char strinput[MAXLEN], strupwd[TOKLEN], struname[TOKLEN] ; WiFiClient client = wifiserver.available(); //--------------------------------------- // debug // authorized=true; strcpy(strinput, ""); strcpy(strupwd, ""); strcpy(struname, ""); while ( client.connected() ) { if (authorized) return; if ( client.available() ) { char c = client.read(); //read char by request readString = ""; while ( (readString.length() < TOKLEN) && (c != '\n') ) { readString += c; c = client.read(); } readString.toCharArray(strinput, MAXLEN); // cstringarg( char* haystack, char* vname, char* sarg ) // haystack pattern: &varname=1234abc, delimiters &, \n, \0, SPACE, EOF cstringarg(strinput, "uname", struname); // uname cstringarg(strinput, "upwd", strupwd); // upwd // debug Serial.print("strupwd >>>"); Serial.print(strupwd); Serial.println("<<<"); Serial.print("website_upwd>>>"); Serial.print(website_upwd); Serial.println("<<<"); Serial.print("readString>>>");Serial.println(readString); if ( (strlen(strupwd) == strlen(website_upwd)) && (strcmp(website_upwd, strupwd) == 0) ) { authorized = true; //debug //Serial.print("check: authorized="); Serial.println(authorized); readString = ""; return; } //if HTTP request has ended if (c == '\n') { client.flush(); //now output html data header String script = ""; script += ("HTTP/1.1 401 Log-In Required"); script += ("Content-Type: text/html \n"); script += ("\n"); // do not forget this one //???? script += ("<!DOCTYPE html> \n"); script += ("<html> \n"); script += ("<head> \n"); // utf-8 für "°" Zeichen script += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> \n" ; script += "<title>" ; script += website_title ; script += "</title> \n" ; script += "</head> \n" ; script += "<body> \n" ; script += "<h1><p style=\"color:rgb(255,0,191);\"> " + (String)website_url ; script += (String)": <wbr> <wbr> " + "Not authorized !</p> </h1> \n" ; script += ("<h2><p style=\"color:rgb(255,0,191);\"> log in to proceed: </p> </h2> \n"); script += ("<FORM ACTION='/' method=GET > \n"); script += ("<h2>user name: <INPUT TYPE=text NAME='uname' VALUE='' MAXLENGTH='50'> </h2> \n"); script += ("<h2>password : <INPUT TYPE=PASSWORD NAME='upwd' VALUE='' MAXLENGTH='50'> </h2> \n"); script += ("<h2><INPUT TYPE=SUBMIT></h2> \n"); script += ("</FORM> \n"); script += ("<BR> \n"); script += ("</body> \n"); script += ("</html> \n"); client.print(script); //stopping client client.stop(); delay(1); //clearing string for next read //readString = ""; } } delay(1); } }
Zuerst muss der gesamte String vom Browser gelesen werden oder bis TOKLEN erreicht ist. Danach kann man die Parameter mit cstringarg rausfischen und das dann prüfen.
Vorher war es anders herum: Erst wurde der Parameter für Passwort geprüft und dann ein Zeichen von den gesendeten Browserdaten gelesen, das eine Zeichen wurde angehängt und dann begann der Spaß von vorn.
![]()







Zitieren



Lesezeichen