0

如何在我的登录代码上放置一个循环,如果用户第三次输入错误的密码/用户名,程序就会结束?

在这一点上,我很难放置循环代码。

这是我在 VB 2010 中的登录代码

Private Sub btnLogIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogIn.Click
    Me.Refresh()
    Dim login = Me.TblUserTableAdapter1.UsernamePasswordString(txtUser.Text, txtPass.Text)

    If login Is Nothing Then
        MessageBox.Show("Incorrect login details", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Else
        Dim ok As DialogResult
        ok = MessageBox.Show("Login Successful", "Dantiña's Catering Maintenance System", MessageBoxButtons.OK, MessageBoxIcon.Information)
        MMenu.Show()
        MMenu.lblName.Text = "Welcome " & Me.txtUser.Text & " !"
        If txtPass.Text <> "admin" Then
            MMenu.Button1.Enabled = False
            ProdMaintenance.GroupBox1.Visible = True
            MMenu.Button2.Enabled = True
            MMenu.Button3.Enabled = True
            MMenu.Button4.Enabled = True
        Else
            MMenu.Button1.Enabled = True
            ProdMaintenance.GroupBox1.Visible = True
            MMenu.Button2.Enabled = True
            MMenu.Button3.Enabled = True
            MMenu.Button4.Enabled = True
        End If
        Me.Refresh()
        Me.Hide()

    End If

End Sub
4

1 回答 1

1

尝试在方法之外初始化一个计数器,如果密码不正确,则增加计数器

像这样的东西

If login Is Nothing And counter<=3 Then
counter+=1
于 2012-11-09T09:30:57.870 回答