Thread: Login form problem

  1. #1
    Registered User elwood's Avatar
    Join Date
    May 2014
    Posts
    6

    Login form problem

    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:
    1. #include <conio.h>
    2. #include <stdio.h>
    3. #include <dos.h>
    4. #include <process.h>
    5. char passcode[20]={"admin"};
    6. char password[20];
    7. int wc=0; // wrong pass coutner
    8. int lc=0; // wrong log counter
    9. char ch;
    10. int nsb=1; //none stop able to make all while keep running
    11. int i;
    12. void login(){
    13. do{
    14. retry: // loger and log fail checker
    15. clrscr();
    16. gotoxy(30,11); printf("Please select Option");
    17. gotoxy(35,13); printf("1. Login\n");
    18. gotoxy(35,14); printf("2. Help\n");
    19. gotoxy(35,15); printf("3. Exit\n");
    20. gotoxy(30,17); printf("Your Selection: ");
    21. ch=getch();
    22. switch(ch){
    23. case '1':
    24. clrscr();
    25. goto loger;
    26. break;
    27. case '3':
    28. clrscr();
    29. do{
    30. printf("Do you want to exit? Y/N");
    31. ch=getch();
    32. switch(ch){
    33. case '3':
    34. clrscr();
    35. gotoxy(35,13); printf("Exiting...");
    36. delay(1000);
    37. exit(1);
    38. break;
    39. case '4':
    40. clrscr();
    41. gotoxy(35,13); printf("Cancelled!");
    42. delay(1000);
    43. clrscr();
    44. goto retry;
    45. break;
    46. }
    47. }while(nsb!=27);
    48. break;
    49. case '2' :
    50. clrscr();
    51. gotoxy(10,9); printf("Help");
    52. gotoxy(21,13); printf("Default Password is: admin");
    53. gotoxy(21,14); printf("Press any number key to choice option!");
    54. gotoxy(28,16); printf("Press any key to exit...");
    55. getch();
    56. goto retry;
    57. break;
    58. }
    59. }while(nsb!='1');
    60. loger:
    61. clrscr();
    62. if(lc==1){ // count wrong pass
    63. gotoxy(19,24); printf("You have input wrong password for %d time!",wc);
    64. }
    65. gotoxy(30,12); printf("Input Password: ");
    66. //scanf("%s",password);
    67. while(ch!=13) // password hider
    68. {
    69. ch=getch();
    70. if(ch!=13 && ch!=8){
    71. putch('*');
    72. password[i] = ch;
    73. i++;
    74. }
    75. }
    76. password[i] = '\0';
    77. if(wc==2){ // auto exit after 3 time wrong
    78. clrscr();
    79. gotoxy(24,13); printf("Too many wrong input! Exiting...");
    80. delay(1000);
    81. exit(1);
    82. }
    83. if(strcmp(password,passcode)==0){ //correct pass goto main
    84. clrscr();
    85. lc=0;
    86. goto mainloader;
    87. }
    88. else { // wrong pass enable wrong log counter & 3 time wrong exit if not 3 time go to interface
    89. clrscr();
    90. gotoxy(33,13); printf("Wrong Password");
    91. gotoxy(23,14); printf("Wrong 3 Time Program will be Exit!");
    92. wc=wc+1;
    93. lc=1;
    94. getch();
    95. goto retry;
    96. }
    97. mainloader: // main loger load to main
    98. clrscr();
    99. }
    100. void main(){
    101. clrscr();
    102. login();
    103. printf("Text in main");
    104. getch();
    105. }
    Attached Files Attached Files
    • File Type: c 3.c (2.4 KB, 117 views)

  2. #2
    Registered User
    Join Date
    Jul 2012
    Posts
    51
    Quote Originally Posted by elwood View Post
    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!
    Variable 'i' is uninitialized and never reset to 0.

    The code will be easier to read and debug if you use functions instead of goto statements.

  3. #3
    Registered User elwood's Avatar
    Join Date
    May 2014
    Posts
    6
    Quote Originally Posted by fnprintf View Post
    Variable 'i' is uninitialized and never reset to 0.

    The code will be easier to read and debug if you use functions instead of goto statements.
    Awww, Thank you.... It work..
    I will make it into functions. Thank again!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Printing Other Form In C# Form
    By loserone+_+ in forum C# Programming
    Replies: 0
    Last Post: 11-19-2013, 08:16 PM
  2. Replies: 8
    Last Post: 12-08-2009, 12:55 PM
  3. problem with login thingy....
    By Huskar in forum C Programming
    Replies: 4
    Last Post: 03-31-2009, 06:23 PM
  4. Login Form
    By Aga^^ in forum C# Programming
    Replies: 16
    Last Post: 02-04-2009, 08:33 AM
  5. Login Form for program
    By Houssen in forum C++ Programming
    Replies: 3
    Last Post: 03-29-2008, 02:35 PM

Tags for this Thread