Advertisement
Guest User

Untitled

a guest
Nov 28th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. void userLogin(void)
  2. {
  3. int field;
  4. char usernameFile[20], passwordFile[PASSWORD];
  5. char username[20], password[PASSWORD];
  6.  
  7. /* Enter username and password */
  8. printf("Please enter a username: ");
  9. scanf("%s", username);
  10. fflush(stdin);
  11.  
  12. printf("Please enter a password: ");
  13. scanf("%s",password);
  14. fflush(stdin);
  15.  
  16.  
  17. infoEncrypt(username);
  18. infoEncrypt(password);
  19.  
  20.  
  21. /* Opens file in read mode */
  22. FILE *fp = fopen("password.txt", "r+");
  23.  
  24. /* If file cannot be opened/created, it returns an error */
  25.  
  26. if (fp==NULL)
  27. {
  28. printf("Error");
  29. getch();
  30. }
  31. else
  32. {
  33.  
  34. do
  35. {
  36. field = fscanf(fp,"%s %s\n",usernameFile, passwordFile);
  37.  
  38.  
  39. /* Checks to see if username and password is correct */
  40. if(strcmp(username,usernameFile)==0 && strcmp(password,passwordFile)==0)
  41. {
  42. break;
  43.  
  44.  
  45. }
  46.  
  47.  
  48. }while(field == 2);
  49. printf("%i", field);
  50. if(field != 2)
  51. {
  52.  
  53. /* If end of file, username and password isn't correct and re-runs */
  54. system("cls");
  55. welcome();
  56. printf("Please enter a correct username and password.\n\n");
  57. userLogin();
  58. }
  59.  
  60. }
  61. fclose(fp);
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement