记录&显示失败的登录尝试次数 [英] record & display the number of failed login attempts

查看:82
本文介绍了记录&显示失败的登录尝试次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我是大学三年级学生,我们刚刚使用c#在asp中进行身份验证。我们将它们存储在web.config文件中,而不是使用数据库来记录用户名和密码。我需要知道的是,如何记录和显示失败的登录尝试次数。



对于这方面的任何帮助都非常有用。



liamoj

Hi I am a 3rd year college student, we have just moved on to form authentication in asp using c#. Instead of using a database to record usernames & passwords, we are storing them in the web.config file. What I need to know is this, how to record & display the number of failed login attempts.

Will be greatfull for any assistance with this.

liamoj

推荐答案





我有一个类似的无效登录尝试代码,请检查以下代码
Hi,

I have a similar code for invalid login attemps, check below code
private static int cntAttemps = 0;
private void LoginUser()
{
    try
    {
        string userEmail = string.IsNullOrEmpty(txtUserEmail.Text) ? null : txtUserEmail.Text;
        string password = string.IsNullOrEmpty(txtPassword.Text) ? null : txtPassword.Text;

        bool success = CheckLogin(userEmail, password);

        if (!success)
        {
           //error message
            lblInvalidmsg.Text = string.Empty;
            InvalidLoginAttemps();
        }
        else
        {
               //success login message
                cntAttemps = 1;
                dvinvalid.Visible = false;
                lblInvalidmsg.Text = string.Empty;
              //may redirect to some page
        }
    }
    catch (Exception ex)
    {

    }
}

private void InvalidLoginAttemps()
{
    try
    {
        dvinvalid.Visible = true;
        cntAttemps++;
        lblInvalidmsg.Text = "Invalid login attemp(s) " + cntAttemps + ", attemps remaining " + Convert.ToInt32(3 - cntAttemps).ToString();
        if (cntAttemps > 3)
        {
            lblInvalidmsg.Text = "Sorry! your account is block now, please contact your administrator.";
           //code to block user
        }
    }
    catch (Exception ex)
    {

    }
}

这里 CheckLogin 是您比较来自 web.config 的凭据的登录方法将返回 true 如果成功。

Here CheckLogin is your login method to compare credentials from web.config will return true if success.


这篇关于记录&显示失败的登录尝试次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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