首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在给定的持续时间内禁用提交按钮?

问如何在给定的持续时间内禁用提交按钮?
EN

Stack Overflow用户
提问于 2012-03-01 15:12:13
回答 1查看 925关注 0票数 1

我正在建立一个登录表单。如果用户尝试使用无效用户名/密码登录3次,则必须在给定的持续时间内禁用提交按钮。

我该怎么做呢?

下面是我的现有代码:

代码语言:javascript
复制
protected void Button1_Click(object sender, EventArgs e)
{
    int count = 0;
    string username = TextBox1.Text.Trim();
    string password = TextBox2.Text.Trim();
    String connString = ConfigurationManager.ConnectionStrings["Myconnection"].ToString();
    SqlConnection conn = new SqlConnection(connString);
    SqlCommand cmd = new SqlCommand("Login", conn);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@username", username);
    cmd.Parameters.AddWithValue("@password", password);
    conn.Open();
    SqlDataReader read = cmd.ExecuteReader();
    read.Read();

    if (read.HasRows)
    {
        Session["LoggedIn"] = "correct";
        Response.Redirect("WebForm2.aspx", false);
    }
    else
    {
        Label1.Visible = true;
        Label1.Text = "Wrong user/password";
        conn.Close();
    }

    if (System.Convert.ToInt32(ViewState["Tries"]) == 2)
    {
        Label1.Text = "Exceeded 3 times Attempts.Please Login after some time";
        TextBox1.Enabled = false;
        TextBox2.Enabled = false;
        Button1.Enabled = false; // Button1 is the submit button
    }
    else
    {
        // Otherwise, increment number of tries.
        ViewState["Tries"] = System.Convert.ToInt32(ViewState["Tries"]) + 1;
        if (System.Convert.ToInt32(ViewState["Tries"]) == 2)
            Label1.Text = "Exceeded 3 times Attempts.Please Login after some time";
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-01 15:18:38

为此,您可以在代码或数据库中创建一个表,如下所示

代码语言:javascript
复制
LockingTime

Userid   LockTime  LockedDateTime
1          30       01/03/2012 12:30

根据此表

代码语言:javascript
复制
UserId = id of the user locked
LockTime - amount of time user Get locked
LockDateTime - DateTime when user account locked

当用户登录失败三次时,以explained...

  • Now的身份在表中输入数据当用户尝试登录系统时,您应该检查

select * from table name userid=@userid and GetDate() > DATEADD (mi, LockTime, LockDateTime)

注意:查询只是一个提示,而不是实际的查询,因为我没有添加锁定日期+锁定时间,这取决于可用的数据库和函数

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9512053

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档