Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Read in the userName and password stored on the file and asssign them to the variables 'fileUserName' and 'filePassword'
- fscanf(loginFile, "%s %s", fileUserName1, filePassword1);
- fscanf(loginFile, "%s %s", fileUserName2, filePassword2);
- fscanf(loginFile, "%s %s", fileUserName3, filePassword3);
- // Do while to keep menu open and to let user keep trying to enter their details
- // Check to see file exists first
- if (loginFile != NULL)
- {
- do
- {
- // Tell the user if the login file has been found
- printf("Login file has been found...\n");
- // Prompt user to enter their password and username
- printf("Please enter your username: ");
- scanf("%s", &userName);
- printf("Please enter your password: ");
- scanf("%s", &password);
- // 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
- // Login Details (1)
- loginSuccess1 = strcmp(userName, fileUserName1);
- loginSuccess2 = strcmp(password, filePassword1);
- // Login Details (2)
- loginSuccess3 = strcmp(userName, fileUserName2);
- loginSuccess4 = strcmp(password, filePassword2);
- // Login Details (3)
- loginSuccess5 = strcmp(userName, fileUserName3);
- loginSuccess6 = strcmp(password, filePassword3);
- // If any of the details match, let the user into the system
- if ((loginSuccess1 == 0 && loginSuccess2 == 0) || (loginSuccess3 == 0 && loginSuccess4 == 0) || (loginSuccess5 == 0 && loginSuccess6 == 0))
- {
- printf("\nCongratulations! Logging you in now.. Enjoy the application.\n");
- printf("\n");
- loginState = 1;
- }
- // Else, tell them their details are correct and let them try again
- else
- {
- printf("Sorry but the details you entered were incorrect.\n");
- }
- } while (loginState == 0);
- }
- else
- {
- printf("Username/Password file containing login info could not be found. Please contact the adminstrator.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement