Started playing with C and CGI forms. Is this code ok? Can it be improved/optimized?
If I fill user with "user" and password with "pass" input in takelogin is user=user&password=pass
In the end I want to have user = 'user'
and pass = 'pass'
This is the form
#include <stdio.h>
int main(void)
{
printf("%s%c%c\n", "Content-Type:text/html;charset=iso-8859-1",13,10);
printf("<title>Takelogin</title>\n");
printf("<h3>Multiplication results</h3>\n");
printf("%s\n", "<form action='/takelogin.cgi' method='post'>");
printf("%s\n", "<div>Your input (80 chars max.):<BR>");
printf("%s\n", "<input type='text' name='user' size='60' maxlength='80'><br>");
printf("%s\n", "<input type='password' name='password' size='60' maxlength='80'><br>");
printf("%s\n", "<input type='submit' value='Send'></div>");
printf("%s\n", "</form>");
return 0;
}
And this is takelogin
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXINPUT 80
int main(void)
{
char *lenstr;
char *user;
char *pass;
char input[MAXINPUT];
long len;
char delim[2][2] = {"&", '='};
printf("%s%c%c\n",
"Content-Type:text/html;charset=iso-8859-1",13,10);
printf("<TITLE>Response</TITLE>\n");
lenstr = getenv("CONTENT_LENGTH");
if(lenstr == NULL)
printf("<P>Error in invocation - wrong FORM probably.");
else {
fgets (input , sizeof(input) , stdin);
char *loginS = malloc(sizeof(input));
strcpy(loginS, input);
user = strtok(loginS, delim[0]);
user = strtok(user, delim[1]);
user = strtok(NULL, delim[1]);
pass = strtok(input, delim[0]);
pass = strtok(NULL, delim[0]);
pass = strtok(pass, delim[1]);
pass = strtok(NULL, delim[1]);
printf("%s@%s", user, pass);
free(loginS);
return 0;
}
return 0;
}