Vb.net 如何在登录时使用计数?
我想让我的登录功能计数,但我不知道如何。我想要的是,当用户输入错误的用户名和密码错误3次,该程序将关闭并显示消息Vb.net 如何在登录时使用计数?,vb.net,authentication,Vb.net,Authentication,我想让我的登录功能计数,但我不知道如何。我想要的是,当用户输入错误的用户名和密码错误3次,该程序将关闭并显示消息 Dim i As Integer If txtUsername.Text = "username" Then If txtPassword.Text = "password" Then MessageBox.Show("I am KING!!") Me.Close() End If E
Dim i As Integer
If txtUsername.Text = "username" Then
If txtPassword.Text = "password" Then
MessageBox.Show("I am KING!!")
Me.Close()
End If
Else
MessageBox.Show("Failed!!")
End If
If (i >= 3) Then
End If
MessageBox.Show("Get Out")
End
请告诉我如何指挥这个。谢谢你你有数据库吗?我还假设您正在开发一个桌面应用程序,根本没有数据库。这只是我所在学院的一项测试工作。你可以在这里找到我的登录系统,它使用了类似的思想:基本上,每次登录尝试都会计算一个会话变量。当这个变量被计算了3次时,它甚至使帐户无法访问。我不清楚增量是多少。每次回发后,
i
的值是否不会重置?我在我的系统上使用了会话(如果我自己这么说的话,它实际上比这个更复杂)。尽管如此,我同意你在这里增加的增量应该是OP想要的+1“Public i As Integer=0”在块“Sub-CheckLogin()”之外,因此当您调用“Sub-CheckLogin()”时,不会将该值重新设置为0
Public i as integer = 0
Public Sub CheckLogin()
If txtUsername.Text = "calvin" Then
If txtPassword.Text = "calvin" Then
MessageBox.Show("I am KING!!")
End If
Else
MessageBox.Show("I am Pig!!")
i += 1 'Increment times by 1
End If
If (i >= 3) Then
End
End If
End Sub