Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "rlutil.h"
- void Login();
- void Register();
- char username[32];
- char password[32];
- char acc[32];
- char pw[32];
- int main()
- {
- int logreg;
- printf("Press '1' For Login");
- printf("Press '2' For Registern");
- logreg = getch();
- printf("n------------------------------------------------n");
- tester:
- ;
- if (logreg == '1')
- {
- Login();
- }
- else if (logreg == '2')
- {
- Register();
- }
- else
- {
- printf("nInvalid Input!!! Choose between '1' or '2' !!!n");
- logreg = getch();
- goto tester;
- }
- return 0;
- }
- void Login()
- {
- start:
- ;
- char answer;
- // Vnesuvanje na username
- printf("nEnter your Username: ");
- scanf("%s",username);
- // Vnesuvanje na Password
- printf("nEnter your Password: ");
- scanf(" %s",password);
- FILE *fData;
- // Otvara file za citanje
- fData = fopen("database.txt", "rt");
- if (!fData)
- {
- printf("The file can not be openednaa");
- }
- int found=0;
- while(!feof(fData) && !found)
- {
- fscanf(fData, "%st%s", acc, pw);
- if (strcmp(username, acc) == 0 && strcmp(password, pw) == 0)
- {
- setColor(LIGHTGREEN);
- printf("nSuccessfuly logged it to our WebSitenn");
- setColor(GREY);
- found = 1;
- getch();
- break;
- }
- else if (!found)
- {
- setColor(LIGHTRED);
- printf("nNo Access to our WebSitenn");
- printf("Invalid username or password!!!nn");
- setColor(GREY);
- printf("Would you like to try again?? [y/n] ");
- answer = getch();
- found = 0;
- printf("nn------------------------------------------------n");
- break;
- }
- }
- fclose(fData);
- tester2:
- ;
- //proverka za Povtorno pustanje na programata
- if (answer== 'y')
- {
- goto start;
- }
- else
- {
- if (answer!='n')
- {
- printf("Please choose between 'y' or 'n' !!!nn");
- answer = getch();
- goto tester2;
- }
- else
- {
- getch();
- return 0;
- }
- }
- }
- void Register()
- {
- char acc[32];
- char pw[32];
- FILE *fData;
- fData = fopen("database.txt", "a");
- if (!fData)
- {
- printf("File could not be openednaa");
- getchar();
- return;
- }
- printf("Enter your desired Username: ");
- scanf("%s", acc);
- printf("Enter your desired Password: ");
- scanf("%s", pw);
- printf("n");
- fprintf(fData, "%st%sn", acc, pw);
- fclose(fData);
- }
- FILE *fData;
- // Otvara file za citanje
- fData = fopen("database.txt", "rt");
- if (!fData)
- {
- printf("The file can not be openednaa");
- }
- int found=0;
- while(!feof(fData) && !found)
- {
- fscanf(fData, "%st%s", acc, pw);
- if (strcmp(username, acc) == 0 && strcmp(password, pw) == 0)
- {
- setColor(LIGHTGREEN);
- printf("nSuccessfuly logged it to our WebSitenn");
- setColor(GREY);
- found = 1;
- getch();
- break;
- }
- else if (!found)
- {
- setColor(LIGHTRED);
- printf("nNo Access to our WebSitenn");
- printf("Invalid username or password!!!nn");
- setColor(GREY);
- printf("Would you like to try again?? [y/n] ");
- answer = getch();
- found = 0;
- printf("nn------------------------------------------------n");
- break;
- }
- }
- fclose(fData);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement