Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<string>
- #include<cstdlib>
- #include<windows.h>
- #include<dos.h>
- #include<math.h>
- #include<conio.h>
- using namespace std;
- class login{
- protected:
- string username,password,securityQuestion;
- string fileUser,filePassword,fileSecQues;
- public:
- login();
- int loginCheck();
- void signUp();
- int forgotPassword();
- };
- login::login()
- {
- int n;
- start_Page:
- cout<<"\n1. Login\n2. Register\n3. forgotPassword\n4. Exit";
- cout<<"\n-----------------------\n";
- cout<<"Enter your choice: ";
- cin>>n;
- int login_retry=0,forgot_try=0;
- switch(n)
- {
- case 1:
- {
- system("cls");
- login_retry=loginCheck();
- if(login_retry>0)
- {
- system("cls");
- cout<<"Wrong Username and password";
- cout<<"\n If you haven't created account then please Sign Up"<<endl;
- goto start_Page;
- }
- }
- break;
- case 2:
- signUp();
- system("cls");
- goto start_Page;
- break;
- case 3:
- system("cls");
- forgot_try=forgotPassword();
- switch(forgot_try)
- {
- case 0:
- break;
- case 1:
- cout<<"There is no such user in our database"<<endl;
- cout<<"Please register to use our services."<<endl;
- break;
- case 2:
- cout<<"Sorry but your answer doesn't match with the answer stored in our database.";
- cout<<"Please try again from the begining.";
- break;
- default:
- cout<<"This is default";
- }
- getch();
- system("cls");
- goto start_Page;
- break;
- case 4:
- exit(2);
- default:
- cout<<"What?? There's no such option.\n Please choose any valid option to proceed";
- goto start_Page;
- }
- }
- void login::signUp()
- {
- system("cls");
- cout<<"Hello there....Lets create a new account\n";
- cout<<"Please fill all the details carefully and remember all the details\n";
- cout<<"Enter Username: ";
- cin>>username;
- cout<<"Enter password: ";
- cin>>password;
- cout<<"For your security purpose please answer this security question: ";
- cout<<"\n IN WHICH COUNTRY YOU WANT YOUR DREAM JOB ?";
- cout<<"\nYour Answer: ";
- cin>>securityQuestion;
- ofstream file;
- file.open("CoolCab2.txt",ios::app);
- file<<username<<' '<<password<<' '<<securityQuestion<<'\n';
- cout<<"Congratulations!!! You have successfully created your account";
- cout<<"\nPlease press any button to continue to the main page";
- getch();
- }
- int login::loginCheck()
- {
- cout<<"Enter Username: ";
- cin>>username;
- cout<<"Enter Password: ";
- cin>>password;
- ifstream file;
- file.open("CoolCab2.txt");
- file.seekg(0);
- while(!file.eof())
- {
- file>>fileUser>>filePassword>>fileSecQues;
- if(username==fileUser && password== filePassword)
- {
- cout<<"Login Successful";
- cout<<"\nCOOLCABS WELCOMES YOU HAVE A SAFE AND NICE TRIP\n";
- getch();
- return 0;
- }
- }
- return 1;
- }
- int login::forgotPassword()
- {
- system("cls");
- cout<<"Enter Username: ";
- cin>>username;
- int userFound=0;
- ifstream file;
- file.open("CoolCab2.txt");
- file.seekg(0);
- while(!file.eof())
- {
- file>>fileUser>>filePassword>>fileSecQues;
- if(username==fileUser)
- {
- userFound=1;
- break;
- }
- }
- if(userFound==1)
- {
- cout<<"Welcome "<<username<<endl;
- cout<<"Please answer your security question:"<<endl;
- cout<<"IN WHICH COUNTRY YOU WANT YOUR DREAM JOB ?";
- cout<<"\nYOur Answer: ";
- cin>>securityQuestion;
- if(securityQuestion==fileSecQues)
- {
- cout<<"Please wait.......Searching the database.......";
- Sleep(2000);
- cout<<"\nSearch Complete";
- cout<<"\nYour password is: "<<filePassword;
- getch();
- return 0;
- }
- else
- return 2;
- }
- return 1;
- getch();
- }
- int main()
- {
- login l;
- l.loginCheck();
- l.signUp();
- }
Add Comment
Please, Sign In to add comment