subject

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.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 22:30
You draw two cards from a standard deck of 52 cards, but before you draw the second card, you put the first one back and reshuffle the deck. (a) are the outcomes on the two cards independent? why?
Answers: 3
question
Computers and Technology, 24.06.2019 11:30
Why is body language an important factor in a business meeting
Answers: 1
question
Computers and Technology, 24.06.2019 17:40
Create a file called favorite_foods, and list your favorite foods, entering five or six or more. press enter after each favorite food so it appears on its own line (make certain you also press enter after the final food item). after the file is created, add two more foods you like that are not on the list (press enter after the final food item). view the list of foods to make certain the two items you added appear at the end of the list
Answers: 2
question
Computers and Technology, 24.06.2019 18:30
*write a program that defines symbolic names for several string literals (chars between quotes). * use each symbolic name in a variable definition. * use of symbolic to compose the assembly code instruction set can perform vara = (vara - varb) + (varc - vard); ensure that variable is in unsigned integer data type. * you should also further enhance your symbolic logic block to to perform expression by introducing addition substitution rule. vara = (vara+varb) - (varc+vard).
Answers: 1
You know the right answer?
Credential file is a file that holds important information about users, including their usernames an...
Questions
question
Mathematics, 20.01.2021 19:50
question
English, 20.01.2021 19:50
question
Mathematics, 20.01.2021 19:50
question
Mathematics, 20.01.2021 19:50
question
Mathematics, 20.01.2021 19:50
question
Mathematics, 20.01.2021 19:50
question
Chemistry, 20.01.2021 19:50
Questions on the website: 13722360