Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- User login()
- {
- ifstream flogin("users.dat",ios::binary);
- if(!flogin)
- {
- cout<<"No accounts have been created. Please restart and create an account first.";
- getch();
- exit(1);
- }
- else
- {
- char uname[15],pword[15];
- User u;
- int flag;
- int counter=0;
- a:
- system("cls");
- if(counter!=0)
- {
- flogin.open("users.dat",ios::binary);
- }
- flogin.seekg(0,ios::beg);
- cout<<"Username: ";
- fflush(stdin);
- gets(uname);
- while(flogin.read((char*)&u,sizeof(u)))
- {
- if(strcmp(uname,u.username)==0)
- {
- b:
- flag=0;
- system("cls");
- cout<<"Password: ";
- fflush(stdin);
- gets(pword);
- if(strcmp(pword,u.password)==0)
- {
- break;
- }
- else
- {
- cout<<"Wrong password. Please try again.";
- getch();
- goto b;
- }
- }
- else
- {
- flag=1;
- }
- }
- if(flag==1)
- {
- cout<<"Username does not exist. Try again.("<<(3-counter)<<" tries left)";
- getch();
- flogin.close();
- counter++;
- if(counter>=4)
- {
- exit(1);
- }
- else
- {
- goto a;
- }
- }
- else if(flag==0)
- {
- flogin.close();
- getch();
- return u;
- }
- }
- }
Add Comment
Please, Sign In to add comment