Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<conio.h>
  4. using namespace std;
  5.  
  6. struct user
  7. {
  8. string name;
  9. string birth;
  10. string pass;
  11. };
  12.  
  13. int loginMenu();
  14. int loginPage();
  15. void activeMenu();
  16. void checkMenu(int x);
  17. void registerOption();
  18. bool checkLogin(string username,string password);
  19.  
  20. int main()
  21. {
  22. checkMenu(loginMenu());
  23. }
  24.  
  25. int loginMenu()
  26. {
  27. system("cls");
  28. int option;
  29. cout<<"(1) Login"<<endl
  30. <<"(2) Register"<<endl
  31. <<"(3) Exit"<<endl
  32. <<"\nOption: ";
  33. cin >>option;
  34.  
  35. return option;
  36. }
  37.  
  38. void checkMenu(int x)
  39. {
  40. if(x == 1)
  41. {
  42. loginPage();
  43. }
  44. else if(x == 2)
  45. registerOption();
  46. else if(x == 3)
  47. {
  48. exit(0);
  49. }
  50. else
  51. {
  52. cout<<"Invalid Option";
  53. system("pause");
  54. checkMenu(loginMenu());
  55. }
  56. }
  57.  
  58. void registerOption()
  59. {
  60. system("cls");
  61.  
  62. ofstream databaseName;
  63. databaseName.open("databaseName.dat",std::ios_base::app);
  64. ofstream databaseBirth;
  65. databaseBirth.open("databaseBirth.dat",std::ios_base::app);
  66. ofstream databasePass;
  67. databasePass.open("databasePass.dat",std::ios_base::app);
  68.  
  69. user User;
  70. cout<<"Username: ";
  71. cin.ignore();
  72. getline(cin,User.name);
  73. databaseName<<User.name<<endl;
  74. cout<<"Birthday: ";
  75. getline(cin,User.birth);
  76. databaseBirth<<User.birth<<endl;
  77. cout<<"Password: ";
  78. getline(cin,User.pass);
  79. databasePass<<User.pass<<endl;
  80.  
  81. databaseName.close();
  82. databaseBirth.close();
  83. databasePass.close();
  84.  
  85. cout<<User.name<<" "<<User.birth<<"\nRecord Saved"<<endl;
  86. system("pause");
  87. checkMenu(loginMenu());
  88. }
  89.  
  90. int loginPage()
  91. {
  92. system("cls");
  93. char option;
  94. string username, password;
  95. cout<<"Enter Username: ";
  96. cin.ignore();
  97. getline(cin,username);
  98. cout<<"Password: ";
  99. char PIN[20];
  100.  
  101.  
  102. int i = 0;
  103. while (1)
  104. {
  105. PIN[i] = _getch(); //getch() - get character without echo
  106. if (PIN[i] == 13) // enter key =13
  107. {
  108. PIN[i] = '\0'; //='terminating the C-String variable
  109. break;
  110. }
  111. else if (PIN[i] == 8 && i > 0)
  112. {
  113. cout << "\b \b";
  114. i--;
  115. }
  116.  
  117. else if (PIN[i] == 8) // use this code when backspace issue
  118. {
  119. cout << " \b";
  120. }
  121. else
  122. {
  123. cout << "*";
  124. i++;
  125. } //13 is ASCII value for Enter
  126. }
  127.  
  128. if (checkLogin(username, PIN))
  129. activeMenu();
  130. else
  131. {
  132. do
  133. {
  134. system("cls");
  135. cout<<"Invalid Username or Password"<<endl
  136. <<"Try again? [y/n]: ";
  137. cin >>option;
  138. if(option == 'y'||option == 'Y')
  139. loginPage();
  140. else if(option == 'n'||option == 'N')
  141. checkMenu(loginMenu());
  142. else
  143. {
  144. cout<<"Invalid option"<<endl;
  145. system("pause");
  146. }
  147. }while(option != 'n' || option != 'N' || option != 'y' || option != 'Y');
  148. }
  149. }
  150.  
  151. bool checkLogin(string username,string password)
  152. {
  153. ifstream databaseName;
  154. databaseName.open("databaseName.dat");
  155. ifstream databasePass;
  156. databasePass.open("databasePass.dat");
  157.  
  158. string line, pass;
  159. int value = 0;
  160. while(getline(databaseName,line) && getline(databasePass,pass))
  161. {
  162. if(line == username && pass == password)
  163. value = 1;
  164. }
  165. if(value == 1)
  166. return true;
  167. else
  168. return false;
  169.  
  170. databaseName.close();
  171. databasePass.close();
  172. }
  173.  
  174. void activeMenu()
  175. {
  176. system("cls");
  177. int option;
  178. cout<<"(1) Profile"<<endl
  179. <<"(2) News Feed"<<endl
  180. <<"(3) Post"<<endl
  181. <<"(4) Search"<<endl
  182. <<"(5) Special"<<endl
  183. <<"(6) Logout"<<endl
  184. <<"\nOption: ";
  185. cin >>option;
  186.  
  187. if(option == 1)
  188. cout<<"Hello";
  189. else if(option == 2)
  190. cout<<"Hello";
  191. else if(option == 3)
  192. cout<<"Hello";
  193. else if(option == 4)
  194. cout<<"Hello";
  195. else if(option == 5)
  196. cout<<"Hello";
  197. else if(option == 6)
  198. checkMenu(loginMenu());
  199. else
  200. cout<<"Hello";
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement