Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
main()


{
int i,counter=0,flag=0,log;
printf("Enter 1 to login")
switch(log)
{
    case 1:
char uid[25],pwd[25],s_uid[][25]={"user1","user2","user3"};
char s_pwd[][25]={"Pwd1","Pwd2","Pwd3"},ch='a';/*dummy character in ch */
printf("\n Enter the user id : ");
scanf("%s",uid);
printf("\n Enter the password : ");
i=0;
while(1)
{
    ch=getch();
    if(ch==13)
    break;
    else if(ch==8)
    {       if(i!=0) /*this is for avoiding the ENTER instructions getting deleted */
        {
            printf("\b");  /*printing backspace to move cursor 1 pos back*/
            printf("%c",32);/*making the char invisible which is already on console*/
            printf("\b"); /*printing backspace to move cursor 1 pos back*/
            i--;
            pwd[i]='\0';
        }
        else
        continue;
    }
    else
    {
    putchar('*');/* char - '*' will be printed instead of the character */
    pwd[i]=ch;
    i++;
    }
}
pwd[i]='\0';
for(i=0;i<=2;i++)
{
    if((stricmp(uid,s_uid[i]))==0 && (strcmp(pwd,s_pwd[i]))==0)
    {
        flag=1;
        break;
    }
}
if(flag) printf(" \n \n \t \t USER AUTHENTICATED ");
else printf("\n \n \n\t TRESSPASSERS WILL BE SHOT AND SURVIVORS WILL BE SHOT AGAIN :)");
}
getch();
}
Posted
Updated 17-Nov-15 3:55am
v2
Comments
Patrice T 17-Nov-15 12:20pm    
Try to improve the question with a couple sentences that make a question.
George Jonsson 18-Nov-15 18:34pm    
Do you want your application to be running while you are blocking the user or will the application exit after 3 failed attempts?

1 solution

it fairly easy: you must somehow save the time after the first login failure and than wait til the time is over. In Windows you can use the Sleep function.

That logic fits best in an outter loop of your code.

Some meta-code
C++
bool loginSuccess = false;

do {
   long startTime = gettime():
   //your login code
   
 loginSuccess = ...;//get state

  if( !loginSuccess ) { 
   Sleep( ... )
 }

} while( !loginSuccess );
 
Share this answer
 
Comments
George Jonsson 18-Nov-15 18:21pm    
Blocking the user like this will probably drive him or her crazy. At least I would try to kill the application if it lets me wait for 2 minutes without a chance to exit.
Better to let the loop run and check the time for every login attempt.
You also need to put the variable startTime outside the loop.
KarstenK 20-Nov-15 3:14am    
He has the freedom to make his own choices - as you. Dont ferget it!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900