i am trying to make a program that reads a username and password from a txt file
then makes you log in and checks to see if the username && password are correct. i am still confused on how to use txt files in C++. how to read from them the most is what i need. Thank you very much.
#include "stdafx.h"
#include <iostream> // library that contains basic input output functions
#include <string> // library for c++ strings
#include <fstream> //helps open and close files
usingnamespace std;
int main()
{
//Username and Password to validate credentials
//strings in which user will enter username and password
ifstream inputStream; //ifstream means Input File stream
string username, password;
int passattempts = 0;
inputStream.open("c:/filename.txt"); //if the file is in with the header files/folder of the initial program you do not need to make a pathname
//Checking if user's entered credentials are equal to actual USERNAME and PASSWORD
string USERNAME, PASSWORD;
inputStream >> USERNAME;
inputStream >> PASSWORD;
do{
// Prompting user to input username
cout << "Enter Username : ";
cin >> username;
//Checking if username length is less than 4 characters then display an error message
if (username.length() < 4)
{
cout << "Username length must be atleast 4 characters long.";
}
else //if username length is greater than 3
{
//promprting user for password
cout << "Enter Password : ";
cin >> password;
//Checking if password length is less than 6 characters then display an error message
if (password.length() < 6)
{
cout << "Password length must be atleast 6 characters long.";
}
if (username == USERNAME)//if password length is greater than 5
{
cout << "Checking Username.";
system("pause");
}
else
{
//looking to check another username from the file.
}
{
if (username == USERNAME && password == PASSWORD)
{
cout << "User credentials are correct!!!" << endl;
break;
}
else
{
cout << "Invalid login details" << endl;
++passattempts;
}
}
}
} while (passattempts != 3);
system("pause");
return (0);
}