Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main(void)
- {
- printf("Content-type:text/html\n\n");
- printf("<html><body>");
- int validLogin=0;
- int ch = 1;
- int numberOfLines = 0;
- int counter = 0;
- char *enteredUsername;
- char *enteredPassword;
- char holding[100];
- char username[30];
- char password[12];
- fgets(username, 30, stdin);
- fgets(password, 12, stdin);
- strcpy(holding, username);
- strcat(holding, password);
- char *token;
- char *secondToken;
- token = strtok(holding, "=");
- enteredUsername = strtok(NULL, "&");
- printf("%sa", enteredUsername);
- strcat(enteredUsername, "\0");
- secondToken = strtok(NULL, "=");
- enteredPassword = strtok(NULL, "\0");
- printf("%sa", enteredPassword);
- char existingUsers[20];
- char existingPasswords[12];
- FILE *users = fopen("users.txt", "r");
- do
- {
- ch = fgetc(users);
- if(ch == '\n'){
- numberOfLines++;
- }
- }while (ch != EOF);
- numberOfLines++;
- if(ch != '\n' && numberOfLines != 0){
- numberOfLines++;
- }
- rewind(users);
- fgets(existingUsers, 20, users);
- while(counter < numberOfLines)
- {
- if((strcmp(enteredUsername, existingUsers))==0)
- {
- printf("Username is true!");
- fgets(existingPasswords, 20, users);
- if(strcmp(enteredPassword, existingPasswords)==0)
- {
- validLogin = 1;
- break;
- }
- else
- {
- validLogin = 0;
- break;
- }
- }
- if(counter == (numberOfLines-1))
- {
- validLogin = 0;
- }
- fgets(existingUsers, 20, users);
- counter++;
- }
- if (validLogin == 1)
- {
- printf("Successful Login! Continue Here.");
- }
- else if(validLogin == 0)
- {
- printf("Unsuccesful Login </br>");
- printf("<a href= \"http://cgi.cs.mcgill.ca/~ebruch/loginandregister.html\" target=\"blank\"> Click Here to Try Again </a>");
- }
- return(0);
- printf("</body></html>");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement