Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- bool authenticate(char* usr,char *pwd)
- {
- char user[10];
- char password[10];
- char userAuth[10];
- char passAuth[10];
- strcpy(user,usr);
- strcpy(password,pwd);
- FILE *readfile;
- readfile=fopen("users.txt", "r");
- while (fscanf(readfile,"%s %s", userAuth,passAuth) != EOF)
- {
- if ((strcmp(user,userAuth) == 0) && (strcmp(password,passAuth) == 0))
- {
- printf ("Authenticated.. moving on to console..\n");
- return true;
- }
- }
- fclose(readfile);
- return false;
- }
- void createNewUser()
- {
- char username[10];
- char password[10];
- FILE *appendfile;
- appendfile=fopen("users.txt", "a");
- printf("\nEnter a username: ");
- scanf("%s", username);
- printf("Enter a password: ");
- scanf("%s", password);
- fprintf(appendfile, "%s ",username);
- fprintf(appendfile, "%s\n",password);
- printf ("\nNew user added.\n");
- fclose(appendfile);
- }
- void viewInfo()
- {
- char user[10];
- char pass[10];
- FILE *readfile;
- readfile=fopen("users.txt", "r");
- printf("\nHere are a list of users on the system:\n\n");
- while (fscanf(readfile,"%s %s",user,pass) != EOF)
- printf("Username: %s | Password: %s\n",user, pass);
- printf("\nList completed...\n");
- fclose(readfile);
- }
- // wanna overwrite the RET to 004011E0 and we're crashing at 42415a59
- int main(int argc, char* argv[])
- {
- char usr[50];
- char pwd[50];
- bool run = true;
- int selection=0;
- printf("Please enter username: ");
- scanf("%s",usr);
- printf("Please enter a password: ");
- scanf("%s",pwd);
- if (!(authenticate(usr,pwd)))
- {
- printf("access denied!\n");
- return 0;
- }
- while (run)
- {
- printf("\n******MENU*******\n");
- printf("[1] Add a user to the system\n");
- printf("[2] View current list of users on system\n");
- printf("[3] EXIT\n");
- printf("\nselection: ");
- scanf("%i",&selection);
- if (selection == 1)
- createNewUser();
- else if (selection == 2)
- viewInfo();
- else if (selection == 3)
- run = false;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement