尝试不锁定帐户失败 [英] Unsuccessful Attempts not locking account

查看:114
本文介绍了尝试不锁定帐户失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在登录页面上有一个代码,如果该帐户获得3次失败的登录尝试,该代码将锁定该帐户.问题是,当用户尝试使用相同的用户名但使用不同的密码登录时,该帐户未锁定.我在数据库中看不到登录尝试次数.请帮我.我怎么了?

I have a code on the login page that will lock the account if the account gets 3 unsuccessful login attempts. The problem is that when a user tries to login with the same username but different password the account does not lock. I don''t see the login attemps in the database. Please help me. What did I wrong?

if (!IsPostBack)
        {
            Session["counter"] = 0;     
        }
        else
        {
            Session["counter"] = Convert.ToInt32(Session["counter"]) + 1;

            using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString))
            {
                con.Open();

                string cmdStr = "Select count(*) from Table22 where EmailAddress=@TextBoxEA";
                SqlCommand sqlCmd = new SqlCommand(cmdStr, con);
                sqlCmd.Parameters.Add("@TextBoxEA", TextBoxEA.Text);
                int userExists = (int)sqlCmd.ExecuteNonQuery();

                cmdStr = "Select count(*) from Table22 where EmailAddress = @TextBoxEA AND Password = @TextBoxPW";
                sqlCmd = new SqlCommand(cmdStr, con);
                sqlCmd.Parameters.Add("@TextBoxEA", TextBoxEA.Text);
                sqlCmd.Parameters.Add("@TextBoxPW", TextBoxPW.Text);
                int correctPassword = (int)sqlCmd.ExecuteNonQuery();

                

                string msg = "";
                if (userExists == 0)
                    msg = "alert('User Name Does Not Exist You Must Fill Out Registration First');";
                else if (correctPassword == 0)
                    msg = "alert('Invalid UserName / Password');";
                else if (Convert.ToInt32(Session["counter"]) >= 3)
                {
                    msg = "alert('The Account is Locked');";


                    cmdStr = "Update Table22 SET isLocked = true where EmailAddress = @TextBoxEA";
                    sqlCmd = new SqlCommand(cmdStr, con);
                    sqlCmd.Parameters.Add("@TextBoxEA", TextBoxEA.Text);
                    sqlCmd.ExecuteNonQuery();
                }
                if (msg.Length > 0)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", msg, true);
                    TextBoxEA.Text = string.Empty;
                }
                con.Close();
            } 

        }
    }



新错误:



New Error:

 Invalid column name 'true'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'true'.

Source Error:


Line 54:                     sqlCmd = new SqlCommand(cmdStr, con);
Line 55:                     sqlCmd.Parameters.Add("@TextBoxEA", TextBoxEA.Text);
Line 56:                     sqlCmd.ExecuteNonQuery();
Line 57:                 }
Line 58:                 if (msg.Length > 0)

推荐答案

认为我已经在
cmdStr = "Update Table22 SET isLocked = true where EmailAddress = @TextBoxEA";


SQL中本身没有布尔列类型-您需要使用

a)(最佳方式)BIT,如果为True,则将值设置为1;如果为False,则将其值设置为0


There isn''t a Boolean column type per se in SQL - you need to use

a) (best way) BIT and set the value to 1 if True or 0 if False

cmdStr = "Update Table22 SET isLocked = 1 where EmailAddress = @TextBoxEA";


或b)CHAR(1),如果为True,则将值设置为"Y",如果为False,则将值设置为"N"


OR b) CHAR(1) and set the value to ''Y'' if True or ''N'' if False

cmdStr = "Update Table22 SET isLocked = ''Y'' where EmailAddress = @TextBoxEA";


或c)(不要这样做)VARCHAR(5)并将值设置为"True"或"False"


OR c) (Don''t do this) VARCHAR(5) and set the value to ''True'' or ''False''

cmdStr = "Update Table22 SET isLocked = ''True'' where EmailAddress = @TextBoxEA";


这篇关于尝试不锁定帐户失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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