Question

In: Computer Science

Create a C++ login program using file for 2 user. Usernames must be in one file...

Create a C++ login program using file for 2 user. Usernames must be in one file and password in the other file. Ask user for their usernames and password if it matches, they logged in successfully. If it doesn’t match,they have 3 trials ,then they have to sign in and create a username and password. After creating a username and password, they have to go to the login page again. Must work for visual studio code

Solutions

Expert Solution

SOURCE CODE

/* In this program we shall assume that the username and passwords are stored in such a way that the position of the username matches the position of its corresponding password */

#include <iostream>

#include <fstream>

//macro defining the number of usernames to be handled by program

#define USER_COUNT 2

using namespace std;

//function prototypes

void read_username(string [], fstream &);

void read_pass(string [], fstream &);

bool check_pass(string, string *, int);

int check_username(string, string *);

int main()

{

//defining variables

fstream username_file, pass_file;

string usernames[2], passwords[2];

//reading usernames from a file

read_username(usernames, username_file);

//reading passwords from a file

read_pass(passwords, pass_file);

string username, password;

int index;

//prompt to enter username

cout << "\nEnter username: "; cin >> username;

//check if username exists, if it exists store the index number

//of username in a variable

index = check_username(username, usernames);

//if username exists, ask for password

if(index != -1)

{

cout << "Enter password: "; cin >> password;

//chek password

if(check_pass(password, passwords, index))

cout << "Verified. Username and password match";

else

cout << "Invalid password";

}

//if username does not exixt

else

cout << "Invalid username...\nExiting...";

return 0;

}

//this function reads all usernames from a file and stores it in an array of strings

void read_username(string usernames[], fstream &file)

{

//opening the file

file.open("username.txt", ios::in);

//check if file was opened successfully

if(!file)

{

cout << "\nError opening file...";

return;

}

int i = 0;

string temp;

//read the file contents one by one and store in array

while(file >> temp)

{

usernames[i] = temp;

i++;

}

//close the file

file.close();

}

//this function reads all passwords from a file and stores it in an array of strings

void read_pass(string passwords[], fstream &file)

{

//opening the file

file.open("password.txt", ios::in);

//check if file was opened successfully

if(!file)

{

cout << "\nError opening file...";

return;

}

int i = 0;

string temp;

//read the file contents one by one and store in array

while(file >> temp)

{

passwords[i] = temp;

i++;

}

//close the file

file.close();

}

//this function checks the existence of username and returns the index of its position in array

int check_username(string username, string usernames[])

{

for(int i = 0; i < USER_COUNT; i++)

if(usernames[i] == username)

return i;

return -1;

}

//this function matches a username against its password

bool check_pass(string password, string passwords[], int index)

{

return passwords[index] == password;

}

//username.txt

user1@dumb
user2@smart

//password.txt

user1pass
user2pass

OUTPUT


Related Solutions

Write a JAVA program by making a LOGIN form using Excel file for validation. if user...
Write a JAVA program by making a LOGIN form using Excel file for validation. if user is found, display the user's First Name and Last Name.
create a program that will verify a user's login credentials. The program should prompt the user...
create a program that will verify a user's login credentials. The program should prompt the user to enter his/her username and password at the keyboard. Then it should read the data from a data file named "login.txt". The file "login.txt" will contain a list of 3 valid usernames and passwords to verify the login information supplied by a user.  If the username and password entered by the user matches one of the sets read from the file, the program should print...
C++ Language Create Login Register program without open .txt file simple program also if you can...
C++ Language Create Login Register program without open .txt file simple program also if you can hide password input option menu 1) Login 2) Register 3) exit
Create this C++ program using classes 1. Create a file text file with a string on...
Create this C++ program using classes 1. Create a file text file with a string on it 2. Check the frecuency of every letter, number and symbol (including caps) 3. Use heapsort to sort the frecuencys found 4. Use huffman code on the letters, symbols or numbers that have frecuencys I created the file, and the frecuency part but i'm having trouble with the huffman and heapsort implementation.
C++ : Write a program that creates a login name for a user, given the user's...
C++ : Write a program that creates a login name for a user, given the user's first name, last name, and a four-digit integer as input. Output the login name, which is made up of the first five letters of the last name, followed by the first letter of the first name, and then the last two digits of the number (use the % operator). If the last name has less than five letters, then use all letters of the...
Write a program that reverses a text file by using a stack. The user interface must...
Write a program that reverses a text file by using a stack. The user interface must consist of 2 list boxes and 3 buttons. The 3 buttons are: Read - reads the text file into list box 1. Reverse - reverses the items in list box 1 by pushing them onto stack 1, then popping them from stack 1 (in the reverse order) and adding them to list box 2. Write - writes the contents of list box 2 to...
Create a c++ program with this requirements: Create an input file using notepad ( .txt )...
Create a c++ program with this requirements: Create an input file using notepad ( .txt ) . When testing your program using different input files, you must change the filename inside your program otherwise there will be syntax errors. There are a finite number of lines to be read from the data file. But we can’t assume to know how many before the program executes; so, the standard tactic is to keep reading until you find the “End of File”...
Using C++ Create a program that asks the user to input a string value and then...
Using C++ Create a program that asks the user to input a string value and then outputs the string in the Pig Latin form. - If the string begins with a vowel, add the string "-way" at the end of the string. For “eye”, it will be “eye-way”. - If the string does not begin with a vowel, first add "-" at the end of the string. Then rotate the string one character at a time; that is, move the...
Create a c++ program that: Create an input file using notepad ( .txt ). When testing...
Create a c++ program that: Create an input file using notepad ( .txt ). When testing your program using different input files, you must change the filename inside your program otherwise there will be syntax errors. There are a finite number of lines to be read from the data file. But we can’t assume to know how many before the program executes; so, the standard tactic is to keep reading until you find the “End of File” marker. Input date...
Phyton Login program To start the program each day the manager must login. The main (manager)...
Phyton Login program To start the program each day the manager must login. The main (manager) window will appear with a login, create password, and cancel button. A password must exist for the login button to be enabled. The password is created in a separate window and must be 9 characters or more, and it must have at least on digit, uppercase and lowercase letter. The program will continue to show error messages and prompt for a password until a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT