Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int log()
- {
- FILE *file, *pipe;
- bool isWrong = true;
- char usern[25], pass[25], temp[25];
- puts("Enter your username: ");
- scanf("%s", usern);
- puts("Enter your password: ");
- scanf("%s", pass);
- /* Check if file is opened */
- file = fopen("record.txt", "r");
- if(!file)
- {
- printf("ERROR: FILE COULD NOT BE READ!an");
- exit(1);
- }
- pipe = popen("open ssl pass", "r");
- /* Open the file, read until the end. If the user name is found, check the password entered */
- while(fgets(temp, 25, file)!= NULL && isWrong){
- if((strstr(temp, usern)) != NULL)
- {
- if((strstr(temp, pass))!=NULL)
- {
- isWrong = false;
- printf("Welcome %sn", usern);
- return 1;
- }
- else
- return 2;
- }
- }
- fclose(file);
- }
- /* The newUser function allows a user to register their name and password. */
- void newUser(){
- FILE *file, *pipe;
- int i;
- char usern[25], pass[25];
- puts("Enter a username: ");
- scanf("%s", usern);
- puts("Enter a password: ");
- scanf("%s", pass);
- clear();
- /* Don't be a noob and open the file to write, otherwise every time you register a new user, you'll overwrite the old info :| Open it to append! */
- file = fopen("record.txt", "a");
- if(!file) /* Checks if the file is opened */
- {
- printf("ERROR FILE COULD NOT BE OPENEDan");
- exit(1);
- }
- pipe = popen("openssl passwd", "w");
- if(pipe != NULL)
- {
- fwrite(pass, sizeof(char), strlen(pass), pipe);
- pclose(pipe);
- }
- /* Writes the file */
- fprintf(file, "%st%sn", usern, pass);
- pclose(pipe);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement