Question

1. Create a program to verify a user name and password given by a user 2. Create a text file named correctData.txt (You wil

GA. C:\Windows\system32\cmd.exe Login Username :MyName Jeff Password:11111111 Invalid username or password. You have 2 remain

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Short Summary:

  • Provided the source code and output for the requirement mentioned.

Source Code:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

// declare Function prototype here
void login();
bool checkCredentials(string ,string );
void getUserInput(string &,string &);

string myArray[2];
string userName;
string password;

// stating point of the program
int main () {
string line;
int index = 0;
// stream of file
ifstream inputFile ("correctData.txt");
// check if the file is open
if (inputFile.is_open()) {
// read each line from file
while (getline (inputFile,line))
{
// adding the line to array
myArray[index] = line;
// incrementing the index value
index++;
}
inputFile.close();
}
else{
cout << "Error opening the file";
}
login();
return 0;
}

// usre input of username and password
void getUserInput(string &userName,string &password){
cout << "Login" << endl;
cout << "\nUsername : ";
cin >> userName;
cout << endl;
cout << "Password : ";
cin >> password;
cout << endl;
}

// method to accomplish the task
void login(){
  
getUserInput(userName,password);
  
if(checkCredentials(userName, password)){
cout << "Login successful! \nPress any key to continue" << endl;
}
else {
cout << "Invalid Username or password. You have 2 remaining."<< endl;
getUserInput(userName,password);
  
if(checkCredentials(userName, password)){
cout << "Login successful! \nPress any key to continue" << endl;
}
  
else{
cout << "Invalid Username or password. You have 1 remaining." <<endl;
getUserInput(userName,password);
  
if(checkCredentials(userName, password)){
cout << "Login successful! \n Press any key to continue" << endl;
}
else
cout << "Attempts exceeded.\n Press any key to continue"<<endl;
}
}
}

// validate user name and password.
bool checkCredentials(string userName,string password){
return (myArray[0] == userName && myArray[1] == password);
}

Refer the following screenshots for code indentation:#NC cude <LUStream> main.cpp correctData.txt : 2 #include <fstream> 3 #include <string> 4 5 using namespace std; 6 7 // decla} 54 - void login(){ 55 56 getUserInput(userName, password); 57 58 if(checkCredentials(userName, password)){ 59 cout << Logi

Sample Run:

1)

Login Username: test Password : 1234 Invalid Username or password. You have 2 remaining. Login Username : test Password : 123

2)

Login Username : test Password : 12345 Login successful! Press any key to continue ... Program finished with exit code 0 Pres

******************************************************************************

Feel free to rate the answer and comment your questions, if you have any.

Please upvote the answer and appreciate our time.

Happy Studying!!!

******************************************************************************

Add a comment
Know the answer?
Add Answer to:
1. Create a program to verify a user name and password given by a user 2....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in python 5.23 Login Create a program that prompts the user for a username and password....

    in python 5.23 Login Create a program that prompts the user for a username and password. The correct username should be python and the correct password should be csci 135. See below for example output. (Different messages depending on if user name or password are correct.) Only allow the user to make 3 attempts. Welcome to my secret program! Please enter your username: Trish Please enter your password: Duce Invalid username and password Please enter your username: Trish Please enter...

  • Lab: User login system (python) Create a user login system. Your code should do the following:...

    Lab: User login system (python) Create a user login system. Your code should do the following: 1.Load your user database from “UD.txt” (USE THE EXACT FILE NAME, file is given in the folder) 2.Display “Login or create a new user? Select L to login, select C to create new user.” 3. If wrong selection is entered, take the user back to step 2. 4. If the user entered “L”, display “Please enter your user name and hit enter” 5. Check...

  • Using Python INST-FS-IAD-PROD.INS LAB1 Lab: Create User Account 2. get-password() #promt the user and create password, check the password fits the requirement USE the EXACT file names! Create a user...

    Using Python INST-FS-IAD-PROD.INS LAB1 Lab: Create User Account 2. get-password() #promt the user and create password, check the password fits the requirement USE the EXACT file names! Create a user login system. Your code should do the following: 3, create-user_name() #use this function to create the user name 1.Create your user database called "UD.txt", this should be in CSV format 4, write-file() #user this function to save the user name and password into "UD.txt" Deliverables: Sample: the data you saved...

  • C++ (1) Write a program to prompt the user for an input and output file name....

    C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...

  • Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The progra...

    Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...

  • Create a folder named "TrainerApp". In that folder create the following files. Create a PHP file,...

    Create a folder named "TrainerApp". In that folder create the following files. Create a PHP file, "insert-user-form.php", with a form that has the following fields: - First Name (text) - Last Name (text) - Email (text) - Password (text) - Submit button Create another PHP file, "insert-exercise-form.php" with a form that has the following fields: - Exercise Name (text) - Description (text) - Demonstration Image (file) - Submit button Create another PHP file, "login-user-form.php" with a form that has the...

  • Create a python script to manage a user list that can be modified and saved to...

    Create a python script to manage a user list that can be modified and saved to a text file. Input text file consisting of pairs of usernames and passwords, separated by a colon (:) without any spaces User choice: (‘n’-new user account, ‘e’-edit existing user account, ‘d’- delete existing user account, ‘l’- list user accounts, ‘q’-quit) List of user accounts, error messages when appropriate Output text file consisting of pairs of username and passwords, separated by a colon (:) without...

  • I) will create a rudimentary (and highly insecure) database for the storage of only the user...

    I) will create a rudimentary (and highly insecure) database for the storage of only the user generated identities. This program will have the following behaviors: (line break, 11 pt) ) - Prior to prompting for a new username, the existing list of usernames should be read and loaded to an array. 1 ) Read the list from "users.txt", a prompt is not necessary. Do not change this data file name "users.txt". 2 ) The existing list of usernames should be...

  • Can someone fix the program below so it does what the picture says it won't work...

    Can someone fix the program below so it does what the picture says it won't work for me. import java.util.Scanner; public class Userpass { static String arr[]; static int i = 0; public static void main(String[] args) { String username, password; int tries = 0, result; do { System.out.print("Enter the username: "); username = readUserInput(); System.out.print("Enter the password: "); password = readUserInput(); result = verifyCredentials(username, password); tries++; if (result == -1) System.out.println("The username is incorrect!\n"); else if (result == -2)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT