43 lines
810 B
C
43 lines
810 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define MAX_RETRIES 2
|
|
|
|
int main(void) {
|
|
|
|
char passwd[100];
|
|
|
|
printf("Digite a sua senha para ser salva: ");
|
|
fgets(passwd, 100, stdin);
|
|
|
|
passwd[strcspn(passwd, "\n")] = '\0';
|
|
|
|
int granted = 0;
|
|
|
|
for (int tries = 0; tries <= MAX_RETRIES && granted == 0; tries++) {
|
|
char input[100];
|
|
|
|
printf("Digite a sua senha de acesso: ");
|
|
fgets(input, 100, stdin);
|
|
|
|
input[strcspn(input, "\n")] = '\0';
|
|
|
|
if (strcmp(passwd, input) == 0) {
|
|
granted = 1;
|
|
} else {
|
|
printf("Senha incorreta! %d tentativa(s) restante(s).\n",
|
|
MAX_RETRIES - tries);
|
|
}
|
|
}
|
|
|
|
if (granted == 1) {
|
|
printf("Acesso liberado!\n");
|
|
} else {
|
|
printf("Acesso bloqueado!\n");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|