如何限制登录尝试? [英] how to limit login attempts?

查看:148
本文介绍了如何限制登录尝试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我不得不限制用户的登录尝试....并更新插入是,如果用户超过了数据库的IsBlocked栏目登录尝试

HI i have to limit the login attempts of the user....and update insert the "yes" if the user exceeds login attempts in the "IsBlocked" column of database

我的工作code ...我不知道什么在我的codeI着icrement错误的failedattempts .....这里是codeI上午

i am working on code...i don't know whats the error in my code i cant icrement the failedattempts.....here is the code i am working on

          SqlConnection con2 = new SqlConnection(connstring);
            string cmd1 = "select Emp_IsBlocked from dbo.PTS_Employee where Emp_Username='" + EmployeeName + "' and Emp_Password='" + Password + "'";
            SqlCommand mycomm2 = new SqlCommand(cmd1, con2);
            con2.Open();
            Object Blocked = mycomm2.ExecuteScalar();
            con2.Close();
            if (Blocked != null)
            {
                if (Blocked.ToString() == "")
                {
                    Response.Redirect("~/Transactions.aspx");
                }
                else
                {
                    lblError.Text = "You are Temporarily Blocked for Exceeding Max Number of Login Attempts";
                }
            }

            else
            {
                _failedAttempts++;
                //lblError.Text = ("Fail. " + (3 - _failedAttempts));

                if (_failedAttempts == 3)
                {
                    SqlConnection con1 = new SqlConnection(connstring);
                    SqlCommand mycomm1 = new SqlCommand("SP_IsBlocked", con1);
                    mycomm1.CommandType = CommandType.StoredProcedure;
                    con1.Open();
                    mycomm1.Parameters.Add("@IsBlocked", SqlDbType.VarChar).Value = "Yes";
                    mycomm1.ExecuteNonQuery();
                    con1.Close();
                    lblError.Text = "You are Temporarily Blocked for Exceeding Max Number of Login Attempts";
                }


            } 

可以说任何什么错在上面code或怎么办呢......?

can any say whats wrong in the above code or how to do it....?

推荐答案

替换您的else语句

       else
        {
            _failedAttempts++;
            //lblError.Text = ("Fail. " + (3 - _failedAttempts));

            if (_failedAttempts == 3)
            {
                SqlConnection con1 = new SqlConnection(connstring);
                SqlCommand mycomm1 = new SqlCommand("SP_IsBlocked", con1);
                mycomm1.CommandType = CommandType.StoredProcedure;
                con1.Open();
                mycomm1.Parameters.Add("@IsBlocked", SqlDbType.VarChar).Value = "Yes";
                mycomm1.ExecuteNonQuery();
                con1.Close();
                lblError.Text = "You are Temporarily Blocked for Exceeding Max Number of Login Attempts";
            }


        } 

有了这个,并尝试

With this and try

        else
        {
            object FailedLoginCounter = this.Page.Cache["UserKey_" + this.txtPwd.Text];
            if (FailedLoginCounter == null)
            {
                FailedLoginCounter = 0;
            }
            this.Page.Cache["UserKey_" + this.txtPwd.Text] = (int)FailedLoginCounter + 1;
            if (((int)this.Page.Cache["UserKey_" + this.txtPwd.Text]) == 3)
            {
                SqlConnection con1 = new SqlConnection(connstring);
                SqlCommand mycomm1 = new SqlCommand("SP_IsBlocked", con1);
                mycomm1.CommandType = CommandType.StoredProcedure;
                con1.Open();
                mycomm1.Parameters.Add("@IsBlocked", SqlDbType.VarChar).Value = "Yes";
                mycomm1.ExecuteNonQuery();
                con1.Close();
                lblError.Text = "You are Temporarily Blocked for Exceeding Max Number of Login Attempts";
            }
        }

这篇关于如何限制登录尝试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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