Hello, I have problem with c login form. The password can input for 3 time and if wrong password for 3 times program will be auto close. But there a problem. After I have input a wrong password for the first time, it say incorrect passwords this is ok, but after that even i use the correct password it still load and say incorrect password. But If i input the correct password for the first time it let me login to the main.Please help me to fix this problem! Thank you and sorry for bad english. Here is the code http://pastebin.com/DNwWRAzG
Code:
- #include <conio.h>
- #include <stdio.h>
- #include <dos.h>
- #include <process.h>
- char passcode[20]={"admin"};
- char password[20];
- int wc=0; // wrong pass coutner
- int lc=0; // wrong log counter
- char ch;
- int nsb=1; //none stop able to make all while keep running
- int i;
- void login(){
- do{
- retry: // loger and log fail checker
- clrscr();
- gotoxy(30,11); printf("Please select Option");
- gotoxy(35,13); printf("1. Login\n");
- gotoxy(35,14); printf("2. Help\n");
- gotoxy(35,15); printf("3. Exit\n");
- gotoxy(30,17); printf("Your Selection: ");
- ch=getch();
- switch(ch){
- case '1':
- clrscr();
- goto loger;
- break;
- case '3':
- clrscr();
- do{
- printf("Do you want to exit? Y/N");
- ch=getch();
- switch(ch){
- case '3':
- clrscr();
- gotoxy(35,13); printf("Exiting...");
- delay(1000);
- exit(1);
- break;
- case '4':
- clrscr();
- gotoxy(35,13); printf("Cancelled!");
- delay(1000);
- clrscr();
- goto retry;
- break;
- }
- }while(nsb!=27);
- break;
- case '2' :
- clrscr();
- gotoxy(10,9); printf("Help");
- gotoxy(21,13); printf("Default Password is: admin");
- gotoxy(21,14); printf("Press any number key to choice option!");
- gotoxy(28,16); printf("Press any key to exit...");
- getch();
- goto retry;
- break;
- }
- }while(nsb!='1');
- loger:
- clrscr();
- if(lc==1){ // count wrong pass
- gotoxy(19,24); printf("You have input wrong password for %d time!",wc);
- }
- gotoxy(30,12); printf("Input Password: ");
- //scanf("%s",password);
- while(ch!=13) // password hider
- {
- ch=getch();
- if(ch!=13 && ch!=8){
- putch('*');
- password[i] = ch;
- i++;
- }
- }
- password[i] = '\0';
- if(wc==2){ // auto exit after 3 time wrong
- clrscr();
- gotoxy(24,13); printf("Too many wrong input! Exiting...");
- delay(1000);
- exit(1);
- }
- if(strcmp(password,passcode)==0){ //correct pass goto main
- clrscr();
- lc=0;
- goto mainloader;
- }
- else { // wrong pass enable wrong log counter & 3 time wrong exit if not 3 time go to interface
- clrscr();
- gotoxy(33,13); printf("Wrong Password");
- gotoxy(23,14); printf("Wrong 3 Time Program will be Exit!");
- wc=wc+1;
- lc=1;
- getch();
- goto retry;
- }
- mainloader: // main loger load to main
- clrscr();
- }
- void main(){
- clrscr();
- login();
- printf("Text in main");
- getch();
- }