Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
void genpass(int, int);
void check(int, int, int);
int main ()
{
srand(time(NULL));
int i, c = 0, password, EnteredPassword;
genpass(i, password);
check(c, EnteredPassword, password);
return 0;
}
void genpass (int i, int password)
{
FILE *pf;
pf = fopen("sifra.txt", "w");
fprintf(pf, "");
for (i=0;i<4;i++){
password = ( rand()%10 );
fprintf(pf, "%d", password);
}
printf("\n New password has been generated \n");
fclose(pf);
}
void check(int c, int EnteredPassword, int password)
{
printf("\n Enter your password: ");
scanf("%d", &EnteredPassword);
printf("\n You entered %d password \n", EnteredPassword);
if(password == EnteredPassword)
{
printf("\n Successfully logged in \n");
}
else
{
printf("\n Password incorrect \n Please try again \n");
for ( c = 0; c < 3; c++)
{
printf("\n Enter your password: ");
scanf("%d", &EnteredPassword );
if(password == EnteredPassword)
{
printf("\n Successfully logged in \n");
break;
}
}
}
}
Here is what I need to do:
I need to make a program that's gonna generate 4 random digits ( code ). that part is easy. after that we are putting that code in password.txt file. easy. and then.. if you enter wrong code 3 times, that code from password.txt will delete and you need to write how many times content of password.txt has been deleted. after that you need to make UI where you can generate new code, and to check if you need to generate new code or if it's not yet deleted, how many times you can type it wrong. If you are left with 1 attempt, program will alert you that you only have 1 more attempt. if you get the code right, program will tell you that you now have access to something
And.. I'm already stuck on part where I need to check password. If I enter password from .txt document it will just tell me that it's not correct. What's wrong?