且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在3次无效登录尝试后阻止用户

更新时间:2023-12-04 11:52:58

您可以随时查看.Net中的成员资格服务框架,而不是自己滚动。 。



或者,

添加一个整数FailedLogin列,每次登录失败时增加,成功登录时设置为0。



添加布尔锁定列,如果失败计数超过您的触发水平,则设置为true。



还有其他方式这样做,但这可能是最简单的。
Rather than roll your own, you could always look at the membership services frameworks within .Net.

Alternatively,
Add an integer FailedLogin column, increment that each failed login, set to 0 on successful login.

Add a Boolean Locked column, if failed count exceeds your trigger level, set to true.

There are other ways of doing this, but that is probably the simplest.




在下面的代码我解释了逻辑,如何实现它。如果您需要任何说明,请告诉我。

Hi,
In below code I have explained the logic , how to implement that. If you need any clarifications do let me know.
int NoOfLoginAttempt = 0;
       private void btnLogin_Click(object sender, EventArgs e)
       {
          //Get the User name & Password from the text box
           //Connect to database and get the user details
          if(FOUND )
          {
               if(Password is matched)
               {
                   if(NoOfLoginAttempt ==3)
                   {
                       //connect to database and set the blockFlag=true;
                       //Inform the user that, your account is blocked.
                   }
                   else
                   {

                       NoOfLoginAttempt++;
                       //Show message box to usr to re-enter the password again
                   }
               }
          }
       else
        {
           //show the message box "user not exist"
       }
   }




***的问候

Muthuraja



Best Regards
Muthuraja


关注答案在5次登录尝试后阻止用户15分钟 [ ^ ],建议使用 SqlMembershipProvider [ ^ ]。



谢谢......
Follow the answer Block user for 15 minutes after 5 login attempts[^], which suggests to use SqlMembershipProvider[^].

Thanks...