Asp.net 阻止输入文本框1小时
我有一个问题,从昨天起我就一直想解决。 我知道如何阻止用户的文本框输入,这很简单,但现在我想在一个特定的时间(1小时)内这样做。是指用户输入密码超过3次的情况 这意味着我需要创建一个倒计时,这是我被阻止的点。 所以我试着用定时器。但是当我用TextBoxTimer\u Tick方法中的断点调试程序时 此事件永远不会触发 以下是我编写的一些代码:Asp.net 阻止输入文本框1小时,asp.net,vb.net,Asp.net,Vb.net,我有一个问题,从昨天起我就一直想解决。 我知道如何阻止用户的文本框输入,这很简单,但现在我想在一个特定的时间(1小时)内这样做。是指用户输入密码超过3次的情况 这意味着我需要创建一个倒计时,这是我被阻止的点。 所以我试着用定时器。但是当我用TextBoxTimer\u Tick方法中的断点调试程序时 此事件永远不会触发 以下是我编写的一些代码: Private TextBoxTimer As New Timer() Dim TextboxCompteur As Integer Private
Private TextBoxTimer As New Timer()
Dim TextboxCompteur As Integer
Private Sub TbxUtilisateur_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles TbxUtilisateur.TextChanged
AddHandler TextBoxTimer.Tick, AddressOf TextBoxTimer_Tick
TextBoxTimer.Interval = 1000 'Every 1 seconde
TextBoxTimer.Enabled = True
TextboxCompteur = 10 'during 10 secondes the textbox will be blocked for test
.
. some other code
.
End Sub
Protected Sub TextBoxTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
TextboxCompteur -= 1
If Not TextboxCompteur = 0 Then Exit Sub
TextBoxTimer.Enabled = False
TextBoxTimer.Dispose()
RemoveHandler TextBoxTimer.Tick, AddressOf TextBoxTimer_Tick
TbxMotDePasse.ReadOnly = False
End Sub
也许有人会看到我错过了什么?
否则,如果你对如何处理这个问题有其他想法,我正在听
谢谢你以后的回答 在这样的web应用程序中,您无法轻松使用计时器;相反,您应该实现一个解决方案,在您决定将用户锁定一小时时,更新一个数据库列,该列将用户锁定到当前时间后一小时。以下是伪代码:
bool Login(string username, string password){
User x = DoDbLookupForUser(username)
//user table has USERNAME, HASHEDPASSWORD, WRONGATTEMPTSCOUNTER, LOCKEDOUTUNTILDATE columns
if x == null
throw new UserNotFoundException
if DateTime.Now < x.LockedOutUntilDate
throw new UserLockedOutException
if x.HashedPassword != Hash(password){
x.WrongAttemptsCounter++
if x.WrongAttemptsCounter >= 3
x.LockedOutUntilDate = DateTime.Now.AddHours(1)
SaveUser(x)
throw new UserPasswordIncorrectException
}
x.WrongAttemptsCounter = 0;
SaveUser(x)
return true
}
bool登录(字符串用户名、字符串密码){
用户x=DoDbLookupForUser(用户名)
//用户表有USERNAME、HASHEDPASSWORD、erreattemptsconter、LOCKEDOUTUNTILDATE列
如果x==null
抛出新的UserNotFoundException
如果DateTime.Now=3
x、 LockedOutUntilDate=DateTime.Now.AddHours(1)
保存用户(x)
抛出新UserPasswordIncorrectException
}
x、 错误的尝试中心=0;
保存用户(x)
返回真值
}
尝试3次后,用户被锁定。他们可以在一小时后再试一次。如果他们再犯错误,他们将被再关一个小时。如果你想给他们3个
当您设置日期而不是成功登录时,尝试在一小时内将计数器重置为0。无需将锁定日期重置为空;一旦它成为过去,它就会被忽略。知道用户是否曾经将自己锁在门外,以及何时将自己锁在门外,可能会很方便。您需要在数据库中存储下次允许用户尝试登录的日期时间。Haaaa…当然可以。我很自然地从计时器开始,我是如此的以这种方式思考,以至于我没有以其他方式思考……这是一个好主意,而且真的更简单。