Question
File I/O In this laboratory, we are going to revisit the username-password problem by storing the usernames and passwords in a file. The file will
File I/O
In this laboratory, we are going to revisit the username-password problem by storing the usernames and passwords in a file. The file will consist of a single username and password per line with a space in between.
Create a class PasswordFile which has the following interface :
class PasswordFile { public: PasswordFile(string filename);// opens the file and reads the names/passwords in the vector entry void addpw(string u, string p); //this adds a new user/password to entry and writes entry to the file filename void delpw(string u); //this deletes the user u from the password file bool checkpw(string u, string p); // returns true is user exists and password matches private: string filename; // the file that contains password information vectoruser; // the list of usernames/passwords vector password; // the list of usernames/passwords };
The constructor accepts a filename, and reads the file one-line at a time and adds values to the vectors. The function addpw adds a user/password, and the function delpw deletes a user.
Now create a password.txt file with some entries such as :
jsmith turtle madams apple
Also create a main program to test your classes :
int main() { PasswordFile passfile("password.txt"); passfile.addpw("dbotting","123qwe"); passfile.addpw("egomez","qwerty"); passfile.addpw("tongyu","liberty"); // write some lines to see if passwords match users }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started