Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <cstdio>
- using namespace std;
- void EnterFild(string &, string &);
- void DisplayMenu();
- void AdminMenu();
- void Registration();
- void GetIntoTheSystem(string, string);
- int main() {
- string userlogin;
- string userpassword;
- DisplayMenu();
- GetIntoTheSystem(userlogin, userpassword);
- return 0;
- }
- void EnterFild(string &userlogin, string &userpassword) {
- cout << "Enter the login: ";
- cin >> userlogin;
- cout << "Enter the password: ";
- cin >> userpassword;
- }
- void Registration() {
- string userlogin, userpassword;
- EnterFild(userlogin, userpassword);
- ofstream outFile;
- outFile.open("program.txt", ios_base::app);
- outFile << userlogin << " " << userpassword << endl;
- outFile.close();
- cout << "nn";
- }
- void AdminMenu() {
- ifstream insidFile("program.txt", ios_base::in);
- string line;
- if (insidFile.is_open()) {
- int qtyuser = 1;
- while (!insidFile.eof()) {
- getline(insidFile, line);
- cout << "t#" << qtyuser++ << ": " << line << endl;
- }
- }
- else {
- cerr << "Error, couldn't be opened the file." << endl;
- exit(EXIT_FAILURE);
- }
- }
- void GetIntoTheSystem(string userlogin, string userpassword) {
- ifstream isUserloginTrue("program.txt", ios_base::in);
- string line; int verify;
- string loginAdministrator = "Admin",
- passwordAdministrator = "Admin";
- EnterFild(userlogin, userpassword);
- if (isUserloginTrue.is_open()) {
- while (!isUserloginTrue.eof()) {
- getline(isUserloginTrue, line);
- if (line == userlogin + " " + userpassword) {
- cout << "WELCOME, " << userlogin << endl;
- break;
- }
- else if (userlogin == loginAdministrator && userpassword == passwordAdministrator) {
- cout << "You have been enter as administrator!" << endl;
- cout << " - DISPLAY USERS: " << endl;
- AdminMenu();
- break;
- }
- else {
- for (int verify = 0; verify < 3; verify++) {
- cout << "nUncorrect login or password.ntAttempts to enter left " << 3 - verify << endl;
- EnterFild(userlogin, userpassword);
- if (line == userlogin + " " + userpassword) {
- cout << "WELCOME, " << userlogin << endl;
- }
- else if (userlogin == loginAdministrator && userpassword == passwordAdministrator) {
- cout << "You have been enter as administrator!" << endl;
- cout << " - DISPLAY USERS: " << endl;
- AdminMenu();
- break;
- }
- else {
- if (verify == 2) {
- cout << "nnAccess denied!The number of attempts is limited!nnn" << endl;
- exit(EXIT_SUCCESS);
- }
- }
- }
- }
- }
- }
- else {
- cerr << "Error, couldn't be opened the file." << endl;
- exit(EXIT_FAILURE);
- }
- }
- void DisplayMenu() {
- string userlogin, userpassword;
- int command = 0;
- do {
- cout << "1. Log in system" << endl;
- cout << "2. Registration" << endl;
- cout << "3. Exit" << endl;
- cout << "tPlease select your option(1-3): ";
- cin >> command;
- switch (command) {
- case 1: GetIntoTheSystem(userlogin, userpassword); break;
- case 2: Registration(); break;
- case 3: exit(EXIT_SUCCESS); break;
- }
- } while (command != 3);
- }
- for(...) // цикл по попыткам ввода
- {
- Ввести данные от пользователя;
- if(введенные данные соответствуют данным администратора)
- {
- Залогинить пользователя как администратора;
- return;
- }
- else
- {
- Открыть файл паролей;
- while(файл паролей не закончился)
- {
- Считать строку
- if(строка соответствует введенным пользователем данным)
- {
- залогинить пользователя как обычного пользователя
- return;
- }
- }
- Закрыть файл паролей
- }
- }
- Вывести сообщение о неудаче авторизации.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement