Am working on a password secure web page served by an Arduino for my home project.
At present, my code for the display of text and urls contains a password contained in each link. The password expires after 60 seconds if not used again.
It is added to the web page like this :
// display text and links to browser
// link and text for Command 1
client.print("System : <a href=\"./?");
client.print(passIDvalid);
client.print("DoActionon001");
client.println("\"\">[Command 1]</a>
");
// link and text for Command 2
client.print("System : <a href=\"./?");
client.print(passIDvalid);
client.print("DoActionon002");
client.println("\"\">[Command 2]</a>
");
but on another project, I was getting erratic display of a web page using the method of client.print for each line.
PaulS:
I don't understand why there isn't a separator between the "password" and the command.
Thanks PaulS
The password is not the password that the user enters when first connecting.
When the user enters the password, the code then creates a user session ID, which is the millis at the time when the password was authenticated ( this is the passIDvalid ).
The passIDvalid is then added to the url for all links displayed to that user. Any link clicked by that user will automatically send the ID ( login millis ) to the Arduino as part of the request / instruction.
There is no space because my code looks at the incoming request, separates the request data ( which then contains the passIDvalid + 'DoAction' + Action Number - so anything before 'DoAction' is a possible user session ID ). It then loops thru the 30 possible users and looks for the passIDvalid number to see if it is a valid active user session ID number ( 'active' as the code removes the user from the users array if inactive for xx minutes ) and if it is a valid user session ID, then do Action number xx.
There is no space because my code looks at the incoming request, separates the request data ( which then contains the passIDvalid + 'DoAction' + Action Number - so anything before 'DoAction' is a possible user session ID ).
"separates the request data" how? Delimiters can make that trivial. The absence of them can make it much harder than necessary.
PaulS:
"separates the request data" how? Delimiters can make that trivial. The absence of them can make it much harder than necessary.
Actually the way the code is at the moment, I don't have to separate the incoming request data. I just test to see if the complete request ( session ID + 'DoAction' + Action Number ) matches something I am expecting to receive.
// see if a valid passID exists in the DoAction line
for (int i=0; i < passCount; i++){
if (GotAction == 0 && passIDstart[i] != 0){
ltoa(passIDstart[i],xx1,10); // convert the long to char
// check for the passID + DoAction keyword + action code in the EEbuffer
JoinedChar[0] = '\0'; // clear the destination array
strcat(JoinedChar, xx1); // add the passID to the array
strcat(JoinedChar, DoAction); // add the keyword to the array
strcat(JoinedChar, "on001"); // add the action code to the array
if (strstr(EEbuffer,JoinedChar)) GotAction = 1;
JoinedChar[0] = '\0'; // clear the destination array
strcat(JoinedChar, xx1); // add the passID to the array
strcat(JoinedChar, DoAction); // add the keyword to the array
strcat(JoinedChar, "on002"); // add the action code to the array
if (strstr(EEbuffer,JoinedChar)) GotAction = 2;
My next step is to look at the above code to see if there is a way ( am sure there is, I just have to find it ) to loop all the 'onXXX' codes and set the GotAction variable accordingly, without having to test for each specific 'onXXX' code individually.
PaulS:
"separates the request data" how? Delimiters can make that trivial. The absence of them can make it much harder than necessary.
My next step is to look at the above code to see if there is a way ( am sure there is, I just have to find it ) to loop all the 'onXXX' codes and set the GotAction variable accordingly, without having to test for each specific 'onXXX' code individually.
OK. I think I have this now :
for (int qq=1; qq < 100; qq++){ // check for an action number between 1 and 99
char ActionNum[10]; // local char array to hold the action number being tested
ltoa(qq,ActionNum,10); // convert the qq integer to the ActionNum char array
JoinedChar[0] = '\0'; // clear the destination array
strcat(JoinedChar, xx1); // add the passID to the array
strcat(JoinedChar, DoAction); // add the keyword to the array
strcat(JoinedChar, "on"); // add the action code chrs to the array
strcat(JoinedChar, ActionNum); // add the action number to the array
if (strstr(EEbuffer,JoinedChar)) GotAction = qq; // check if the compiled string exists in the request
}