Advertisement
Guest User

Untitled

a guest
Apr 20th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. // Read in the userName and password stored on the file and asssign them to the variables 'fileUserName' and 'filePassword'
  2. fscanf(loginFile, "%s %s", fileUserName1, filePassword1);
  3. fscanf(loginFile, "%s %s", fileUserName2, filePassword2);
  4. fscanf(loginFile, "%s %s", fileUserName3, filePassword3);
  5.  
  6.  
  7. // Do while to keep menu open and to let user keep trying to enter their details
  8. // Check to see file exists first
  9. if (loginFile != NULL)
  10. {
  11.  
  12. do
  13. {
  14. // Tell the user if the login file has been found
  15. printf("Login file has been found...\n");
  16.  
  17. // Prompt user to enter their password and username
  18. printf("Please enter your username: ");
  19. scanf("%s", &userName);
  20. printf("Please enter your password: ");
  21. scanf("%s", &password);
  22.  
  23. // Compare the string entered by the user to the string in the file and if they are equal, change 'loginState' to 1 so that the do/while can be exited
  24.  
  25. // Login Details (1)
  26. loginSuccess1 = strcmp(userName, fileUserName1);
  27. loginSuccess2 = strcmp(password, filePassword1);
  28.  
  29. // Login Details (2)
  30. loginSuccess3 = strcmp(userName, fileUserName2);
  31. loginSuccess4 = strcmp(password, filePassword2);
  32.  
  33. // Login Details (3)
  34. loginSuccess5 = strcmp(userName, fileUserName3);
  35. loginSuccess6 = strcmp(password, filePassword3);
  36.  
  37. // If any of the details match, let the user into the system
  38. if ((loginSuccess1 == 0 && loginSuccess2 == 0) || (loginSuccess3 == 0 && loginSuccess4 == 0) || (loginSuccess5 == 0 && loginSuccess6 == 0))
  39. {
  40. printf("\nCongratulations! Logging you in now.. Enjoy the application.\n");
  41. printf("\n");
  42. loginState = 1;
  43. }
  44. // Else, tell them their details are correct and let them try again
  45. else
  46. {
  47. printf("Sorry but the details you entered were incorrect.\n");
  48. }
  49.  
  50. } while (loginState == 0);
  51.  
  52. }
  53.  
  54. else
  55. {
  56. printf("Username/Password file containing login info could not be found. Please contact the adminstrator.");
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement