Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help please, the programming language is C. Thank you! Overview of project: The file user.pswd.txt contains usernames, passwords, and additional information. Your program will

Need help please, the programming language is C. Thank you!

image text in transcribedimage text in transcribed

Overview of project: The file "user.pswd.txt" contains usernames, passwords, and additional information. Your program will prompt a user for a username and password, then check if that username password is in the file "user.pswd.txt". If so, your program will print out the additional information for that user that is stored in "user.pswd.txt". If the user enters 3 incorrect username/password attempts, your program terminates. First, think about how to organize your program: What program functionality should be in the main(function ? What functionality should be executed by your own programmer functions? What variables does your main() function need ? What variables does each of your programmer functions need ? Where should you start writing your program: main(function or a programmer function ? Now a little more specifics about the file "user.pswd.txt". The file "user.pswd.txt" is a comma-delimited file. Each field in the file is separated from the next field by a comma. The five fields in "user.pswd.txt" are : lastname, firstname, number of KBytes of data occupied by the user's files, username, password Note that the file user.pswd.txt was created with Notepad.exe, i.e. it has no formatting symbols in it such as those found in Microsoft Word files, etc.. This means that if "user.pswd.txt" contains 100 characters (letters, numbers, blanks, symbols) and 3 newlines, then the file contains exactly 106 bytes (two bytes each for the newlines). Write a program to 1) Notify the program user that they are "attempting to login to a password-protected system". ser 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 *10'. 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 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 fscanfwith 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. Your 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 fscanfwith 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() function will have to close "user.pswd.txt" and then re-open it each time the user enters an incorrect username/password. Overview of project: The file "user.pswd.txt" contains usernames, passwords, and additional information. Your program will prompt a user for a username and password, then check if that username password is in the file "user.pswd.txt". If so, your program will print out the additional information for that user that is stored in "user.pswd.txt". If the user enters 3 incorrect username/password attempts, your program terminates. First, think about how to organize your program: What program functionality should be in the main(function ? What functionality should be executed by your own programmer functions? What variables does your main() function need ? What variables does each of your programmer functions need ? Where should you start writing your program: main(function or a programmer function ? Now a little more specifics about the file "user.pswd.txt". The file "user.pswd.txt" is a comma-delimited file. Each field in the file is separated from the next field by a comma. The five fields in "user.pswd.txt" are : lastname, firstname, number of KBytes of data occupied by the user's files, username, password Note that the file user.pswd.txt was created with Notepad.exe, i.e. it has no formatting symbols in it such as those found in Microsoft Word files, etc.. This means that if "user.pswd.txt" contains 100 characters (letters, numbers, blanks, symbols) and 3 newlines, then the file contains exactly 106 bytes (two bytes each for the newlines). Write a program to 1) Notify the program user that they are "attempting to login to a password-protected system". ser 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 *10'. 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 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 fscanfwith 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. Your 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 fscanfwith 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() function will have to close "user.pswd.txt" and then re-open it each time the user enters an incorrect username/password

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions