如果用户输入错误密码三次,则阻止登录几分钟如何添加以下程序 [英] If user enters wrong password three times, then block the login for some minutes how to add below program

查看:62
本文介绍了如果用户输入错误密码三次,则阻止登录几分钟如何添加以下程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#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();
}

推荐答案

这很简单:你必须以某种方式节省首次登录失败后的时间,而不是等到时间结束了。在Windows中,您可以使用睡眠功能。



该逻辑最适合代码的外部循环。



一些元代码

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
bool loginSuccess = false;

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

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

} while( !loginSuccess );


这篇关于如果用户输入错误密码三次,则阻止登录几分钟如何添加以下程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆