Guest User

Untitled

a guest
Apr 9th, 2018
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4. #include<cstdlib>
  5. #include<windows.h>
  6. #include<dos.h>
  7. #include<math.h>
  8. #include<conio.h>
  9. using namespace std;
  10.  
  11. class login{
  12. protected:
  13. string username,password,securityQuestion;
  14. string fileUser,filePassword,fileSecQues;
  15. public:
  16. login();
  17. int loginCheck();
  18. void signUp();
  19. int forgotPassword();
  20. };
  21.  
  22.  
  23. login::login()
  24. {
  25. int n;
  26. start_Page:
  27. cout<<"\n1. Login\n2. Register\n3. forgotPassword\n4. Exit";
  28. cout<<"\n-----------------------\n";
  29. cout<<"Enter your choice: ";
  30. cin>>n;
  31. int login_retry=0,forgot_try=0;
  32. switch(n)
  33. {
  34. case 1:
  35. {
  36. system("cls");
  37. login_retry=loginCheck();
  38. if(login_retry>0)
  39. {
  40. system("cls");
  41. cout<<"Wrong Username and password";
  42. cout<<"\n If you haven't created account then please Sign Up"<<endl;
  43. goto start_Page;
  44. }
  45. }
  46. break;
  47. case 2:
  48. signUp();
  49. system("cls");
  50. goto start_Page;
  51. break;
  52. case 3:
  53. system("cls");
  54. forgot_try=forgotPassword();
  55. switch(forgot_try)
  56. {
  57. case 0:
  58. break;
  59. case 1:
  60. cout<<"There is no such user in our database"<<endl;
  61. cout<<"Please register to use our services."<<endl;
  62. break;
  63. case 2:
  64. cout<<"Sorry but your answer doesn't match with the answer stored in our database.";
  65. cout<<"Please try again from the begining.";
  66. break;
  67. default:
  68. cout<<"This is default";
  69. }
  70. getch();
  71. system("cls");
  72. goto start_Page;
  73. break;
  74. case 4:
  75. exit(2);
  76. default:
  77. cout<<"What?? There's no such option.\n Please choose any valid option to proceed";
  78. goto start_Page;
  79. }
  80.  
  81. }
  82.  
  83. void login::signUp()
  84. {
  85. system("cls");
  86. cout<<"Hello there....Lets create a new account\n";
  87. cout<<"Please fill all the details carefully and remember all the details\n";
  88. cout<<"Enter Username: ";
  89. cin>>username;
  90. cout<<"Enter password: ";
  91. cin>>password;
  92. cout<<"For your security purpose please answer this security question: ";
  93. cout<<"\n IN WHICH COUNTRY YOU WANT YOUR DREAM JOB ?";
  94. cout<<"\nYour Answer: ";
  95. cin>>securityQuestion;
  96. ofstream file;
  97. file.open("CoolCab2.txt",ios::app);
  98. file<<username<<' '<<password<<' '<<securityQuestion<<'\n';
  99. cout<<"Congratulations!!! You have successfully created your account";
  100. cout<<"\nPlease press any button to continue to the main page";
  101. getch();
  102. }
  103. int login::loginCheck()
  104. {
  105. cout<<"Enter Username: ";
  106. cin>>username;
  107. cout<<"Enter Password: ";
  108. cin>>password;
  109. ifstream file;
  110. file.open("CoolCab2.txt");
  111. file.seekg(0);
  112. while(!file.eof())
  113. {
  114. file>>fileUser>>filePassword>>fileSecQues;
  115. if(username==fileUser && password== filePassword)
  116. {
  117. cout<<"Login Successful";
  118. cout<<"\nCOOLCABS WELCOMES YOU HAVE A SAFE AND NICE TRIP\n";
  119. getch();
  120. return 0;
  121. }
  122. }
  123. return 1;
  124. }
  125.  
  126. int login::forgotPassword()
  127. {
  128. system("cls");
  129. cout<<"Enter Username: ";
  130. cin>>username;
  131. int userFound=0;
  132. ifstream file;
  133. file.open("CoolCab2.txt");
  134. file.seekg(0);
  135. while(!file.eof())
  136. {
  137. file>>fileUser>>filePassword>>fileSecQues;
  138. if(username==fileUser)
  139. {
  140. userFound=1;
  141. break;
  142. }
  143. }
  144. if(userFound==1)
  145. {
  146. cout<<"Welcome "<<username<<endl;
  147. cout<<"Please answer your security question:"<<endl;
  148. cout<<"IN WHICH COUNTRY YOU WANT YOUR DREAM JOB ?";
  149. cout<<"\nYOur Answer: ";
  150. cin>>securityQuestion;
  151. if(securityQuestion==fileSecQues)
  152. {
  153. cout<<"Please wait.......Searching the database.......";
  154. Sleep(2000);
  155. cout<<"\nSearch Complete";
  156. cout<<"\nYour password is: "<<filePassword;
  157. getch();
  158. return 0;
  159. }
  160. else
  161. return 2;
  162. }
  163.  
  164. return 1;
  165. getch();
  166. }
  167. int main()
  168. {
  169. login l;
  170. l.loginCheck();
  171. l.signUp();
  172. }
Add Comment
Please, Sign In to add comment