Не знаю как проверить веденные данные пользователя что бы сравнились с строками из файла. Проблема заключается в одной функции GetIntoTheSystem. проверяет только одну строчку, что нужно дописать-переписать что бы проверялась не только первая строчка файла.
#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 << "\n\n";
}
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.\n\tAttempts 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 << "\n\nAccess denied!The number of attempts is limited!\n\n\n" << 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);
}