I am trying to make a login programme that reads and writes from a textfile. For some reason, only the first line of the textfile works but the rest wont be successful login.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool loggedIn() {
string username, password, un, pw;
cout << "Enter username >> "; cin >> username;
cout << "Enter password >> "; cin >> password;
ifstream read("users.txt");
while (read) {
getline(read, un, ' ');
getline(read, pw);
if (un == username && pw == password) {
return true;
}
else {
return false;
}
}
}
Text File:
user1 pass1
user2 pass2
Alternatives I tried:
read.getline(un, 256, ' ');
read.getline(pw, 256);