Question

In C , checks if the entered password for admin is correct by calling checkAdminPassword. Part...

In C , 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”.

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;
}

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

printf("Enter admin password to add new users:");
char entered_admin_password[50];
scanf("%s", entered_admin_password);
if (checkAdminPassword(entered_admin_password, 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, new_user.firstname, new_user.lastname, new_user.admin);
if (users == NULL) {
return EXIT_FAILURE;
}
}
saveUsers(users, user_count);
free(users);
return EXIT_SUCCESS;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

int checkAdminPassword(char* password, struct user* users, int count) {
for (int i = 0; i < count; ++i) {
if (strcmp((users + i)->username, "admin") == 0) {
if (char==0x08) {
return 1;
}
else {
return 0;
}
}
}
return 0;
}

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

printf("Enter admin password to add new users:");
char entered_admin_password[50];
scanf("%s", entered_admin_password);
if (checkAdminPassword(entered_admin_password, 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, new_user.firstname, new_user.lastname, new_user.admin);
if (users == NULL) {
return EXIT_FAILURE;
}
}
saveUsers(users, user_count);
free(users);
return EXIT_SUCCESS;
}

Add a comment
Know the answer?
Add Answer to:
In C , checks if the entered password for admin is correct by calling checkAdminPassword. Part...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ****Using C and only C**** I have some C code that has the function addRecord, to...

    ****Using C and only C**** I have some C code that has the function addRecord, to add a record to a linked list of records. However, when I run it, the program exits after asking the user to input the address. See picture below: Here is my code: #include<stdio.h> #include<stdlib.h> struct record { int accountno; char name[25]; char address[80]; struct record* next; }; void addRecord(struct record* newRecord) //Function For Adding Record at last in a SinglyLinkedList { struct record *current,*start,*temp;...

  • I need to make it so this program outputs to an output.txt, the program works fine,...

    I need to make it so this program outputs to an output.txt, the program works fine, just need it to fprintf to output.txt #include <stdio.h> #include <string.h> #include <malloc.h> #define MAX 30 struct treeNode { char names[MAX];    struct treeNode *right; struct treeNode *left; }*node; void searchName(char names[], struct treeNode ** parent, struct treeNode ** location) { struct treeNode * ptr, * tempPtr; if(node == NULL)    { *location = NULL; *parent = NULL; return; } if(strcmp(names, node->names) == 0)...

  • Modify the client server system program given below so that instead of sendto() and recvfrom(), you...

    Modify the client server system program given below so that instead of sendto() and recvfrom(), you use connect() and un-addresssed write() and read() calls. //Server.c #include #include #include #include #include #include #include #include #include #include # define PortNo 4567 # define BUFFER 1024 int main(int argc, char ** argv) { int ssd; int n; socklen_t len; char msg[BUFFER]; char clientmsg[BUFFER]; struct sockaddr_in server; struct sockaddr_in client; int max_iterations = 0; int count = 0, totalChar = 0, i = 0;...

  • Lab 3: Databased Admin Tool Python Objective: Develop an admin tool for username and password management. You will need...

    Lab 3: Databased Admin Tool Python Objective: Develop an admin tool for username and password management. You will need to use the best data structure to store the data you read from UD.txt for efficient processing. You can accomplish these tasks with Dictionary or List. The data file (UD.txt) : FIRST NAME, LAST NAME,USERNAME,PASSWORD Sam, DDal,sdd233,Pad231 Dave,Dcon,dcf987, BHYW4fw Dell,Grant,dgr803,Sb83d2d Mike,Kress,mkr212,UNNHS322 Lisa,Kate,lki065,dgw6234 Paul,Edward,ped332,9891ds Youyou,Tranten,ytr876,dsid21kk Nomi,Mhanken,nmh223,3282jd3d2 Write a program that imports the database from UD.txt Give the following options: A: Search by...

  • Lab 4: Databased Admin Tool Continued Python Objective: In the previous lab, you developed an admin tool for username an...

    Lab 4: Databased Admin Tool Continued Python Objective: In the previous lab, you developed an admin tool for username and password management. You accomplished the tasks with Dictionary or List. Here, use class to design your own data structure to accomplish a similar task. The UD.txt datafile: FIRST NAME, LAST NAME,USERNAME,PASSWORD Sam, DDal,sdd233,Pad231 Dave, Dcon,dcf987, BHYW4fw Dell, Grant,dgr803,Sb83d2d Mike, Kress,mkr212,UNNHS322 Lisa,Kate,lki065,dgw6234 Paul,Edward,ped332,9891ds Youyou,Tranten,ytr876,dsid21kk Nomi,Mhanken,nmh223,3282jd3d2 Write a program that imports the database from UD.txt, your program can search for users’ password....

  • Run the code in Linux and provide the screenshot of the output and input #include <signal.h>...

    Run the code in Linux and provide the screenshot of the output and input #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <arpa/inet.h> #include <sys/types.h> #include <sys/socket.h> static void cleanup(); static void docleanup(int signum); static const char *SERVER_ADDR = "127.0.0.1"; static const int SERVER_PORT = 61234; static int cfd = -1; int main(int argc, char *argv[]) { struct sockaddr_in saddr; char buf[128]; int bufsize = 128, bytesread; struct sigaction sigact; printf("client starts running ...\n"); atexit(cleanup); sigact.sa_handler =...

  • Question: For the picture writing question, if the question says that the picture length (height) and...

    Question: For the picture writing question, if the question says that the picture length (height) and width are multiples of 5, then be prepared (for example) to handle a situation where you are being asked to blacken the fourth (vertical) strip from the left. Code: #include #include #include #include #define BUFFER_SIZE 70 #define TRUE 1 #define FALSE 0 int** img; int numRows; int numCols; int maxVal; FILE* fo1; void addtopixels(int** imgtemp, int value); void writeoutpic(char* fileName, int** imgtemp); int** readpic(char*...

  • A CERTAIN program to user's password containing rules such as least n length, one uppercase, lowercase,...

    A CERTAIN program to user's password containing rules such as least n length, one uppercase, lowercase, one digit and white space is given as the code down below. So, simiiar to those rules, I need the code for the following questions post in pictures such as no more three consecutive letters of English alphabets, password should not contain User name and so on. //GOAL: To learn how to create that make strong passwords //Purpose: 1)To learn some rules that makes...

  • I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for.....

    I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for..while..do while,loops,pointer,address,continue,return,break. Create a C++ program which contain a function to ask user to enter user ID and password. The passwordmust contain at least 6 alphanumeric characters, 1 of the symbols !.@,#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20. Save the information. Test the program by entering the User ID and password. The...

  • Need help with shuffle function and give 8 cards to user and computer from shuffle deck?...

    Need help with shuffle function and give 8 cards to user and computer from shuffle deck? #include <stdio.h> #include <stdbool.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <time.h> typedef struct card_s{     char suit;     int face;     struct card_s *listp; } card; void card_create(card* thisNode, char cardSuit, int cardFace, card* nextLoc) {     thisNode->suit = cardSuit;     thisNode->face = cardFace;     thisNode->listp = nextLoc;     return; } void card_insertAfter(card* thisNode, card* newNode) {     card* tmpNext = NULL;    ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT