diff --git a/APL1.1/TP14/lecture.c b/APL1.1/TP14/lecture.c index bd80ffd..6afb062 100644 --- a/APL1.1/TP14/lecture.c +++ b/APL1.1/TP14/lecture.c @@ -6,16 +6,25 @@ int main(int argc, char * argv[]) { char real_password[] = "test 1212 34"; char password[27]; - for (int i = 1; i < argc; i++) { - if (i != 1) strcat(password, " "); - if (strlen(password) + strlen(argv[i]) > 26) { - puts("Mot de passe trop long !"); + printf("Veuillez entrer votre mot de passe : "); + char c; + + for (int i = 0; i < 27; i++) { + if (i < 26) { + c = getchar(); + password[i] = c; + + if (c == '\n') { + password[i] = '\0'; + break; + } + } else if (getchar() != '\n') { + printf("Mot de passe trop long !\n"); return EXIT_FAILURE; } - strcat(password, argv[i]); } - - if (strcmp(password, real_password)) { + + if (strcmp(password, real_password) == 0) { puts("Authentification réussie."); } else puts("Mot de passe incorrect.");