Advertisement
Guest User

Untitled

a guest
Sep 28th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <cstdio>
  5.  
  6. using namespace std;
  7.  
  8. void EnterFild(string &, string &);
  9. void DisplayMenu();
  10. void AdminMenu();
  11. void Registration();
  12. void GetIntoTheSystem(string, string);
  13.  
  14. int main() {
  15. string userlogin;
  16. string userpassword;
  17.  
  18. DisplayMenu();
  19. GetIntoTheSystem(userlogin, userpassword);
  20.  
  21. return 0;
  22. }
  23.  
  24. void EnterFild(string &userlogin, string &userpassword) {
  25. cout << "Enter the login: ";
  26. cin >> userlogin;
  27.  
  28. cout << "Enter the password: ";
  29. cin >> userpassword;
  30. }
  31.  
  32. void Registration() {
  33. string userlogin, userpassword;
  34.  
  35. EnterFild(userlogin, userpassword);
  36.  
  37. ofstream outFile;
  38. outFile.open("program.txt", ios_base::app);
  39. outFile << userlogin << " " << userpassword << endl;
  40. outFile.close();
  41.  
  42. cout << "nn";
  43. }
  44.  
  45. void AdminMenu() {
  46. ifstream insidFile("program.txt", ios_base::in);
  47. string line;
  48.  
  49. if (insidFile.is_open()) {
  50. int qtyuser = 1;
  51. while (!insidFile.eof()) {
  52. getline(insidFile, line);
  53. cout << "t#" << qtyuser++ << ": " << line << endl;
  54. }
  55. }
  56. else {
  57. cerr << "Error, couldn't be opened the file." << endl;
  58. exit(EXIT_FAILURE);
  59. }
  60. }
  61.  
  62. void GetIntoTheSystem(string userlogin, string userpassword) {
  63. ifstream isUserloginTrue("program.txt", ios_base::in);
  64.  
  65. string line; int verify;
  66. string loginAdministrator = "Admin",
  67. passwordAdministrator = "Admin";
  68.  
  69. EnterFild(userlogin, userpassword);
  70.  
  71. if (isUserloginTrue.is_open()) {
  72. while (!isUserloginTrue.eof()) {
  73. getline(isUserloginTrue, line);
  74.  
  75. if (line == userlogin + " " + userpassword) {
  76. cout << "WELCOME, " << userlogin << endl;
  77. break;
  78. }
  79. else if (userlogin == loginAdministrator && userpassword == passwordAdministrator) {
  80. cout << "You have been enter as administrator!" << endl;
  81. cout << " - DISPLAY USERS: " << endl;
  82. AdminMenu();
  83. break;
  84. }
  85. else {
  86. for (int verify = 0; verify < 3; verify++) {
  87. cout << "nUncorrect login or password.ntAttempts to enter left " << 3 - verify << endl;
  88. EnterFild(userlogin, userpassword);
  89.  
  90. if (line == userlogin + " " + userpassword) {
  91. cout << "WELCOME, " << userlogin << endl;
  92. }
  93. else if (userlogin == loginAdministrator && userpassword == passwordAdministrator) {
  94. cout << "You have been enter as administrator!" << endl;
  95. cout << " - DISPLAY USERS: " << endl;
  96. AdminMenu();
  97. break;
  98. }
  99. else {
  100. if (verify == 2) {
  101. cout << "nnAccess denied!The number of attempts is limited!nnn" << endl;
  102. exit(EXIT_SUCCESS);
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }
  109. else {
  110. cerr << "Error, couldn't be opened the file." << endl;
  111. exit(EXIT_FAILURE);
  112. }
  113. }
  114.  
  115. void DisplayMenu() {
  116. string userlogin, userpassword;
  117. int command = 0;
  118.  
  119. do {
  120. cout << "1. Log in system" << endl;
  121. cout << "2. Registration" << endl;
  122. cout << "3. Exit" << endl;
  123. cout << "tPlease select your option(1-3): ";
  124. cin >> command;
  125.  
  126. switch (command) {
  127. case 1: GetIntoTheSystem(userlogin, userpassword); break;
  128. case 2: Registration(); break;
  129. case 3: exit(EXIT_SUCCESS); break;
  130. }
  131. } while (command != 3);
  132. }
  133.  
  134. for(...) // цикл по попыткам ввода
  135. {
  136. Ввести данные от пользователя;
  137. if(введенные данные соответствуют данным администратора)
  138. {
  139. Залогинить пользователя как администратора;
  140. return;
  141. }
  142. else
  143. {
  144. Открыть файл паролей;
  145. while(файл паролей не закончился)
  146. {
  147. Считать строку
  148. if(строка соответствует введенным пользователем данным)
  149. {
  150. залогинить пользователя как обычного пользователя
  151. return;
  152. }
  153. }
  154. Закрыть файл паролей
  155. }
  156. }
  157. Вывести сообщение о неудаче авторизации.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement