Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. bool authenticate(char* usr,char *pwd)
  6. {
  7. char user[10];
  8. char password[10];
  9. char userAuth[10];
  10. char passAuth[10];
  11. strcpy(user,usr);
  12. strcpy(password,pwd);
  13.  
  14. FILE *readfile;
  15. readfile=fopen("users.txt", "r");
  16.  
  17. while (fscanf(readfile,"%s %s", userAuth,passAuth) != EOF)
  18. {
  19. if ((strcmp(user,userAuth) == 0) && (strcmp(password,passAuth) == 0))
  20. {
  21. printf ("Authenticated.. moving on to console..\n");
  22. return true;
  23. }
  24. }
  25.  
  26. fclose(readfile);
  27. return false;
  28. }
  29.  
  30. void createNewUser()
  31. {
  32. char username[10];
  33. char password[10];
  34.  
  35. FILE *appendfile;
  36. appendfile=fopen("users.txt", "a");
  37.  
  38. printf("\nEnter a username: ");
  39. scanf("%s", username);
  40. printf("Enter a password: ");
  41. scanf("%s", password);
  42.  
  43. fprintf(appendfile, "%s ",username);
  44. fprintf(appendfile, "%s\n",password);
  45.  
  46. printf ("\nNew user added.\n");
  47.  
  48. fclose(appendfile);
  49. }
  50.  
  51. void viewInfo()
  52. {
  53. char user[10];
  54. char pass[10];
  55.  
  56. FILE *readfile;
  57. readfile=fopen("users.txt", "r");
  58.  
  59. printf("\nHere are a list of users on the system:\n\n");
  60.  
  61. while (fscanf(readfile,"%s %s",user,pass) != EOF)
  62. printf("Username: %s | Password: %s\n",user, pass);
  63.  
  64. printf("\nList completed...\n");
  65. fclose(readfile);
  66. }
  67.  
  68. // wanna overwrite the RET to 004011E0 and we're crashing at 42415a59
  69. int main(int argc, char* argv[])
  70. {
  71. char usr[50];
  72. char pwd[50];
  73. bool run = true;
  74. int selection=0;
  75.  
  76. printf("Please enter username: ");
  77. scanf("%s",usr);
  78. printf("Please enter a password: ");
  79. scanf("%s",pwd);
  80. if (!(authenticate(usr,pwd)))
  81. {
  82. printf("access denied!\n");
  83. return 0;
  84. }
  85.  
  86. while (run)
  87. {
  88. printf("\n******MENU*******\n");
  89. printf("[1] Add a user to the system\n");
  90. printf("[2] View current list of users on system\n");
  91. printf("[3] EXIT\n");
  92. printf("\nselection: ");
  93. scanf("%i",&selection);
  94.  
  95. if (selection == 1)
  96. createNewUser();
  97. else if (selection == 2)
  98. viewInfo();
  99. else if (selection == 3)
  100. run = false;
  101. }
  102. return 1;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement