Advertisement
Guest User

NewLogin

a guest
Apr 12th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void)
  5. {
  6. printf("Content-type:text/html\n\n");
  7. printf("<html><body>");
  8.  
  9. int validLogin=0;
  10. int ch = 1;
  11. int numberOfLines = 0;
  12. int counter = 0;
  13.  
  14. char *enteredUsername;
  15. char *enteredPassword;
  16. char holding[100];
  17.  
  18. char username[30];
  19. char password[12];
  20. fgets(username, 30, stdin);
  21. fgets(password, 12, stdin);
  22. strcpy(holding, username);
  23. strcat(holding, password);
  24.  
  25.  
  26. char *token;
  27. char *secondToken;
  28.  
  29.  
  30. token = strtok(holding, "=");
  31. enteredUsername = strtok(NULL, "&");
  32. printf("%sa", enteredUsername);
  33. strcat(enteredUsername, "\0");
  34. secondToken = strtok(NULL, "=");
  35. enteredPassword = strtok(NULL, "\0");
  36. printf("%sa", enteredPassword);
  37.  
  38.  
  39. char existingUsers[20];
  40. char existingPasswords[12];
  41.  
  42. FILE *users = fopen("users.txt", "r");
  43.  
  44. do
  45. {
  46. ch = fgetc(users);
  47. if(ch == '\n'){
  48. numberOfLines++;
  49. }
  50. }while (ch != EOF);
  51. numberOfLines++;
  52.  
  53. if(ch != '\n' && numberOfLines != 0){
  54. numberOfLines++;
  55. }
  56.  
  57. rewind(users);
  58. fgets(existingUsers, 20, users);
  59.  
  60.  
  61. while(counter < numberOfLines)
  62. {
  63. if((strcmp(enteredUsername, existingUsers))==0)
  64. {
  65. printf("Username is true!");
  66. fgets(existingPasswords, 20, users);
  67. if(strcmp(enteredPassword, existingPasswords)==0)
  68. {
  69. validLogin = 1;
  70. break;
  71. }
  72. else
  73. {
  74. validLogin = 0;
  75. break;
  76. }
  77. }
  78.  
  79. if(counter == (numberOfLines-1))
  80. {
  81. validLogin = 0;
  82. }
  83. fgets(existingUsers, 20, users);
  84. counter++;
  85. }
  86.  
  87. if (validLogin == 1)
  88. {
  89. printf("Successful Login! Continue Here.");
  90. }
  91. else if(validLogin == 0)
  92. {
  93. printf("Unsuccesful Login </br>");
  94. printf("<a href= \"http://cgi.cs.mcgill.ca/~ebruch/loginandregister.html\" target=\"blank\"> Click Here to Try Again </a>");
  95. }
  96. return(0);
  97.  
  98. printf("</body></html>");
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement