/* Program 2 - Login program: -build a database of names and passwords (3 of them) -password accepted when length >= 6 -give user three chances to input name and password correctly */ #include <stdio.h> #include <string.h> #include <stdlib.h> #define N 50 #define NUM 3 void main() { char names[NUM][N]; char pws[NUM][N]; char pwguess[50]; char nameguess[50]; int i, j; printf("Enter %d names in the format\tname password\n", NUM); for(i=0; i<NUM; i++) { printf("enter name and password %d: ", i); scanf("%s%s", names[i], pws[i]); while(strlen(pws[i])<6) { printf("password must be length >= 6!\n"); printf("enter name and password %d: ", i); scanf("%s%s", names[i], pws[i]); } } printf("\nDatabase of usernames and passwords built!\n\n\n"); for(j=0; j<3; j++) { printf("Enter your name and password: ", nameguess); scanf("%s%s", nameguess, pwguess); for(i=0; i<NUM; i++) { if(strcmp(names[i], nameguess)==0 && strcmp(pws[i], pwguess)==0) { printf("successfully logged in\n"); system("pause"); return; } } printf("incorrect name and password\n"); } printf("Too many login attemps were made. This computer is now locked...\n"); system("pause"); }