Computers and Technology

Credential file is a file that holds important information about users, including their usernames and hashed passwords. The purpose of this program is to add a new user to the credential file. Since only the user admin has the right permissions to manage users (e. g., adding a new user), the program will first retrieve all username and passwords from credential file, stores them in an array of struct user, iterates through the array to find the password (in the hashed form) for user admin, and then asks the user to enter the admin password. Only when the passwords match, the user is asked to provide the information regarding the new user. The program will then add the user to the array of struct user, and then write the updated list of users to credential file.

Consider the struct user used in lab 13.1. In this lab, we will improve the security of our login program by storing usernames and passwords in credential file. credential file has the following format (separated by β€˜\t’):

firstname lastname username password admin
Note that the password stored is H(password), the hash of the original password. You should use the lab ma- chines for this lab, so you should copy over labFileIO. c and credential file to a lab machine first. Open credential file to see its contents.

#define _XOPEN_SOURCE #include #include #include #include

struct user {
char username [50]; char password [256]; char firstname [50]; char lastname [50]; int admin;

};

char* cs221Hash(const char* password) { return crypt(password , "00");

}

struct user* createUsers(int* count) { // Your code goes here

}

void populateUsers(void* users) { // Your code goes here

}

int checkAdminPassword(char* password, struct user* users, int count) { for (int i = 0; i < count; ++i) {

if (strcmp((users + i)->username, "admin") == 0) { if (/* Complete the condition */) {

return 1; }

else {
return 0;

} }

}

return 0; }

struct user* addUser(struct
char* firstname , char* lastname , int // Your code goes here

}

int* count , admin) {

char* username ,

char* password ,

void saveUsers(struct user* users, int count) { // Your code goes here

}

int main(void) {
int user_count = 0;
struct user* users = createUsers(&user_count); if (users == NULL) {

return EXIT_FAILURE; }

populateUsers(users);

new_user. firstname , if (users == NULL) {

return EXIT_FAILURE; }

new_user. lastname ,

new_user. admin);

}
saveUsers(users, user_count); free(users);
return EXIT_SUCCESS;

}

user* users ,

printf (" Enter admin password to add new
char entered_admin_password [50];
scanf("%s", entered_admin_password);
if (checkAdminPassword(entered_admin_p assword, users, user_count)) {

struct user new_user;
printf("Enter username:");
scanf("%s", new_user. username);
printf (" Enter first name :");
scanf("%s", new_user. firstname);
printf (" Enter last name :");
scanf("%s", new_user. lastname);
printf("Enter password:");
scanf("%s", new_user. password);
printf (" Enter admin level :");
scanf("%d", &(new_user. admin));
users = addUser(users , &user_count , new_user. username , new_user. password ,

Implement the following functions. You many not use any square brackets ([]) in your implementation.
Use our special hash function, cs221Hash(), to compute H(password). Because crypt function is inside the library crypt, you need to add -lcrypt to your gcc compiler. You can use the following command to compile your program (assume your code is in file "libFileIO. c"):

$ gcc -std=c99 -o labFileIO labFileIO. c -lcrypt

users :");

1. Complete createUsers, which reads the file credential file, and counts the number of lines in this file . The function, then, dynamically creates an array of struct user based on the number of lines. This function returns the pointer to the array, and also updates count which is the number of users.

2. Complete populateUsers, which reads the file credential file line-by-line, gets the firstname, lastname, 2

username, password and admin from each line to populate users array .

After calling populateUsers, the program asks the user to input the password for username "admin". Then it checks if the entered password for admin is correct by calling checkAdminPassword. Part of this function has been implemented, complete the statement in if(). Keep in mind that the entered password is plaintext whereas the password in struct user is in the hashsed form. The password for user admin is "s#1Pa5".

Complete addUser, which by calling realloc, allocates enough memory space to include the information about the new user. The function then updates the count and returns the pointer of the new array. Keep in mind that password stored in struct user must be in a hashed form.

Complete saveUsers, which write count users in users to the file credential file using the same format as specified.

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 02:00, alexabessin
Aisha has finished working on a word processing document that contains 15 pages. she has added some special elements in the first three pages, page 9 and 10, and page 15 from the document. she wants to print only these pages to see how they look. which option is the correct way to represent (in the print dialog box) the pages that aisha wants to print?
Answers: 3
image
Computers and Technology, 22.06.2019 11:00, loveworld3798
When working with a team you should always do the following, except? question 3 options: be dependable and trustworthy be sensitive to others feelings do your fair share critique members of the group
Answers: 2
image
Computers and Technology, 22.06.2019 12:30, zaratayyibah
Which of the choices sean are not true when considering virus behavior
Answers: 1
image
Computers and Technology, 22.06.2019 14:30, chaparro0512
Create a pseudocode design to prompt a student for their student id and the titles of the three classes they want to add. the solution should display the student’s id and a total bill. β€’ bill a student using the following rules: o students can only add up to 3 classes at a time.
Answers: 3
Do you know the correct answer?
Credential file is a file that holds important information about users, including their usernames an...

Questions in other subjects:

Konu
Mathematics, 23.10.2020 19:40
Konu
Mathematics, 23.10.2020 19:40
Konu
Mathematics, 23.10.2020 19:40