// pages int read_summary_page() { int sum = 0; int bytes_read = 0; char header1 = read_bytes(1, &bytes_read, &sum); // Always 0x10 char header2 = read_bytes(1, &bytes_read, &sum); // Always 0x02 uint16_t command = read_bytes(2, &bytes_read, &sum); if (header1 == 0x10 && header2 == 0x02 && command == 0x2022) { uint16_t length = read_bytes(2, &bytes_read, &sum); uint16_t page_number = read_bytes(2, &bytes_read, &sum); // Page # if (page_number == 0) { // Page #0 if (jouleGPS) { read_ride_summary(&bytes_read, &sum); read_interval_summary(&bytes_read, &sum); read_username(&bytes_read, &sum); read_user_info_record(&bytes_read, &sum); read_ant_info_record(&bytes_read, &sum); } else { read_ride_summary(&bytes_read, &sum); // page still contains 47 interval_summary } int finish = length+6-bytes_read; for (int i = 0; i < finish; i++) { read_bytes(1, &bytes_read, &sum); // to finish } read_bytes(1, &bytes_read, &sum); // checksum } else { if (page_number == 1 && !jouleGPS) { //page still contains 48 interval_summary int finish = length+6-bytes_read; for (int i = 0; i < finish; i++) { read_bytes(1, &bytes_read, &sum); // to finish } read_bytes(1, &bytes_read, &sum); // checksum } // not a summary page ! } } return bytes_read; }
int main(int argc, char **argv) { char username[USERNAME_SIZE]; /* * Write "login: "******"\nFound no user with name: %s\n", username); return 0; } }
int read_userpwd(char *username){ struct pwdb_passwd *pw_entry; pw_entry = pwdb_getpwnam(username); char *password; char salt[2]; strncpy(salt, pw_entry->pw_passwd, 2); password = getpass("password: "******"user name could not be found.\n"); }else if(pwdb_errno==PWDB_FILEERR){ printf("could not access the file.\n");} else if(pwdb_errno==PWDB_MEMERR){ printf("could not allocate memory for the struct pwdb_passwd.\n");} else if(pwdb_errno==PWDB_ENTRERR){ printf("line in PWFILENAME somehow has invalid format.\n"); }return(0); }else{*/ if(strcmp(crypt(password, salt), pw_entry-> pw_passwd)==0){ printf("User authenticated successfully. \n"); pw_entry->pw_failed = 0; pw_entry->pw_age++; pwdb_update_user(pw_entry); if(pw_entry->pw_age>=10){ printf("WOOPS, time to change PW. \n"); } return(1); }else{ if(pw_entry->pw_failed>=5){ printf("User locked. \n"); } pw_entry->pw_failed++; pwdb_update_user(pw_entry); printf("Unknown user or incorrect password. \n"); read_username(username); return(0); } }
void login () { char username[USERNAME_SIZE]; int logged_in = 0; while (!logged_in) { read_username(username); struct pwdb_passwd *p = pwdb_getpwnam(username); if (p == NULL) { printf("\nFound no user with name: %s\n", username); } else { char *passwd = crypt(getpass("password: "******"\nUser authenticated successfully\n"); logged_in = 1; } else { printf("\nUnknown user or incorrect password.\n"); } } } }
int login(struct pwdb_passwd *info){ char username[USERNAME_SIZE]; char password[PASSWORD_SIZE]; /* * Write "login: "******"Locked out!\n"); return 1; } read_password(password); if (was_interrupted) return 1; char *crypted = crypt(password, info->pw_passwd); if (strncmp(info->pw_passwd, crypted, HASH_SIZE) == 0){ login_success(info); printf("Logged in!\n"); return 0; } else { login_failed(info); printf("No!\n"); return 1; } }
int main(int argc,char **argv) { char username[USERNAME_SIZE]; int count = 0; /* write "login:"******"\nFound no user with name: %s\n",username); return(0); } return(0); }
int main(int argc, char **argv) { char username[USERNAME_SIZE]; char *password; // We store in heap, remember to free the memory. char salt[SALT_SIZE]; struct pwdb_passwd *p; // Disable CTRL-C termination signal(SIGINT, SIG_IGN); /* * Write "login: "******"Unsuccessful login."); return 0; } /* * Write "password: "******"password: "******"This account has been locked, please contact an administrator.\n"); } else if (strcmp(password, p->pw_passwd) == 0) { printf("Successful login.\n"); printf("Previous failed logins: %d\n", p->pw_failed); if (p->pw_age > 10) printf("Your password is old, please consider changing it.\n"); write_pw(PW_AGE, p->pw_age + 1, p); write_pw(PW_FAILED, 0, p); start_userterm(p); } else { printf("Unsuccessful login.\n"); write_pw(PW_FAILED, p->pw_failed + 1, p); if (PW_FAILED > 5) write_pw(PW_FAILED, -1, p); } memset(password, '0', strlen(password)); return 0; }