Answered step by step
Verified Expert Solution
Question
1 Approved Answer
help? Write a program to 1) Notify the program-user that they are attempting to login to a password-protected system. 2) Now prompt the program-user for
help?
Write a program to 1) Notify the program-user that they are "attempting to login to a password-protected system". 2) Now prompt the program-user for their username. Read-in the username from the keyboard using a string format descriptor scanf("%s", ..) storing the username in a 100 character array Then prompt the user for their password using another scanf("%s", ..) and store the password in a 20 character array. Note the username character array will contain the characters in the username followed by the string termination character "O'. The same holds for the password array. 3) Now open the password file for reading in your main function. The password file "user.pswd.txt" will be located in the folder from which your program is run. 4) Next, call a subroutine from your main function to check whether the username and password entered by the user are in user.pswd.txt. This subroutine will take three arguments: a FILE pointer to the file "user.pswd.txt", a character array containing a string with the username, and a character array containing a string with the password. 5) Now begin writing the subroutine in 4). Your subroutine receives a FILE pointer for a file that is already opened for reading by the main(function. Your subroutine will need some kind of loop in this subroutine to read through the lines in the file "user.pswd.txt", line- by-line. As your subroutine encounters the next line, it cannot use fscanf(with a string format %s to read the username and password, because theses fields are not separated by white space (blanks, tabs, or new lines); they are separated by commas. Therefore, your subroutine will need two loops (nested within the outer loop that iterates through the lines of the file) to read through the two fields lastname, firstname character-by-character. our code will know that it has reached the end of the lastname field when it encounters a comma, and the same for the firstname field. Then your subroutine will need an fscanf(with a %d format descriptor to read the number of Kbytes. Then your subroutine will need another set of two loops to read the two fields username and password character-by- character. Note that each time that you read a line from user.pswd.txt, store the firstname and the Kbytes value from the line. You will need these in the event that the line in user.pswd.txt has the same username and password as that entered by the user; i.e. that the user of your program is a valid user of the system. Your subroutine could use strcmp to check if the username and password entered by the user matches that of the current line of the file "user.pswd.txt". Or your subroutine could simply compare the username and password fields entered by the user with the current line by comparing character-by-character. In this approach, you will know you have compared the last character entered by the user into the character array when you read a 'V' in the character array. 6) If the program-user enters a valid username and password, greet the user by their first name and indicate to them the number of KBytes of storage that they are currently using. Your subroutine will print this information to the screen, and then return an integer 1 to the main program. 6) If the username or password entered by the program-user does not indicate a valid user, notify the user that the "username or password is invalid", and re-prompt the program-user for a username and password. If the program-user enters 3 incorrect attempts to login, close your program. Note that, based upon what we know so far in the course, your main re-open it each time the user enters an incorrect username/password. function will have to close "user.pswd.txt" and thenStep 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