Posted: February 6th, 2023
Answer the following questions based on this scenario.
Problem: Write a program that reads 10 username and password values into parallel arrays. After the arrays have been loaded, the program should behave like a login screen, prompting for a username and a password. Based on the data read and stored in the arrays, the program should respond appropriately with one of three output messages: “Username not found.”, “Username and password does not match.” or “Access granted.”
Question 1: Would you write this program asking a user to enter the usernames and passwords or would you use a file that contains all the username and passwords as input? Explain why you would choose one over the other.
Question 2: Will your answer remain the same if the number of username and password values change to 40, and why?
SOLUTION
Question 1: The choice between reading the username and password values from the user or from a file depends on the requirements and constraints of the program. If the goal is to provide a secure and user-friendly login screen, it is better to read the values from a file, as it can be more secure than having the user enter their credentials directly into the program. On the other hand, if the program is meant to be simple and quick to set up, it may be more convenient to have the user enter their information directly into the program.
Question 2: The answer remains the same regardless of the number of username and password values, as the choice between reading the information from the user or from a file is independent of the number of values. The same considerations regarding security and ease of use still apply.
Place an order in 3 easy steps. Takes less than 5 mins.