i was wondering if yas could help me with this simple code that i can't get around. There are 2 problems. First i dont know how to ask the password in a way so that ****** will come up on the screen when being typed in. Second of all, i noticed that after the third attempt at the password, if you enter it incorrect, the password will be accepted by passing progress onto the next statement, where i would prefer if the program exited? Heres the code. cheers !
#include <stdio.h>
#include <conio.h>
#include <string.h>
int password(void);
int main()
{
int choice; //variable called choice of type integer
password(); //Calls password function
cprintf("\nAccess accepted !");
getch();
}
int password(void)
{
//Variables
char passwd[10];
int count, correct = 0;
for(count=0;count<3;count++) /*Give user three attempts*/
{
clrscr(); //Call the clear screen function
gotoxy(21,8);
cprintf("**** PASSWORD IS CASE SENSITIVE ****");
gotoxy(26,10);
cprintf("Please Enter Password : ");
cscanf("%s",passwd);
if(strcmp("GOD", passwd)==0)
{
count=3; //Breaks out of for loop
correct = 1; //Allows user into system
}
else
{
gotoxy(25,12);
correct = 0; //Does not allow user into system
textcolor(WHITE); //Sets font colour to white
cprintf("Incorrect Password Entered!!!");
gotoxy(29,13);
cprintf("%d attempt(s) left",3-(count+1));
gotoxy(25,14);
cprintf("Press any key to continue....");
getch(); getch();
}
}
return correct;
}