0

ログイン機能にログイン試行回数を追加したいと考えています。ユーザーが間違ったユーザー名とパスワードを 3 回入力すると、プログラムが終了し、メッセージが表示されます。私のログインボタンのコードは次のForm1.vbとおりです。

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If TextBox1.Text = "13Mendv" And TextBox2.Text = "Admin123" Or
       TextBox1.Text = "Admin" And TextBox2.Text = "Admin123" Or
       TextBox1.Text = "13PateS" And TextBox2.Text = "Staff123" Or
       TextBox1.Text = "13KhetP" And TextBox2.Text = "Member123" Or
       TextBox1.Text = "13PateN" And TextBox2.Text = "Scorer123" Or
       TextBox1.Text = "13ChatP" And TextBox2.Text = "Captain123" Or
       TextBox1.Text = "13BonnN" And TextBox2.Text = "Captain123" Or
       TextBox1.Text = "13EarlJ" And TextBox2.Text = "Captain123" Or
       TextBox1.Text = "13RajaA" And TextBox2.Text = "Captain123" Or
       TextBox1.Text = "1" And TextBox2.Text = "1" Or
       TextBox1.Text = "13SchaJ" And TextBox2.Text = "Captain123" Then
        Timer1.Start() 'Timer on Form1.vb show
        ProgressBar1.Show() 'Progress bar on Form1.vb show
        Label8.Show() 'Label8 on Form1.vb show
        Button4.Show() 'Button4 on Form1.vb show

    Else
        If TextBox1.Text = "" And TextBox2.Text = "" Then
            MsgBox("No Username and/or Password Found!", MsgBoxStyle.Critical, "Error") 'If statement for checking if there is any input in either username or password entry field
        Else
            If TextBox1.Text = "" Then
                MsgBox("No Username Found!", MsgBoxStyle.Critical, "Error") 'Message box no username found
            Else
                If TextBox2.Text = "" Then
                    MsgBox("No Password Found!", MsgBoxStyle.Critical, "Error") 'Message box no password found
                Else
                    MsgBox("Invalid Username And/Or Password!", MsgBoxStyle.Critical, "Error") 'Message box invlaid username and or password
                    TextBox2.Clear()
                End If
            End If
        End If
    End If

End Sub

このコードにカウントを追加して、ユーザーに 3 回のログイン試行の失敗を適切に通知するにはどうすればよいですか?

4

5 に答える 5

1
Public Class Form1    
    Dim attempts As Integer = 0

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim user As String
        user = TextBox1.Text
        If user = "Jhayboy" Then
            MsgBox("Access Granted")
            Form2.Show()
            Me.Hide()

        ElseIf attempts = 3 Then
            MsgBox("Maximum count of retries(3),And you'reach the maximum attempts!Try again later", MsgBoxStyle.Critical, "Warning")
            Close()
        Else
            MsgBox("Username and Password is incorrect! re-enter again you currently have reached attempt " & attempts & " of 3.")

            attempts = attempts + 1
            TextBox1.Text = ""
            TextBox1.Focus()

        End If
    End Sub
End Class
于 2016-03-26T05:50:57.403 に答える
0

cnt を整数として追加し、 cnt<=3 までインクリメントしました。

Private Sub Button1_Click (System.Object としての ByVal 送信者、System.EventArgs としての ByVal e) は、Button1.Click を処理します。

   'Dim cnt As Integer = 0
    If cnt <= 3 Then
        If TextBox1.Text = "13Mendv" And TextBox2.Text = "Admin123" Or
           TextBox1.Text = "Admin" And TextBox2.Text = "Admin123" Or
           TextBox1.Text = "13PateS" And TextBox2.Text = "Staff123" Or
           TextBox1.Text = "13KhetP" And TextBox2.Text = "Member123" Or
           TextBox1.Text = "13PateN" And TextBox2.Text = "Scorer123" Or
           TextBox1.Text = "13ChatP" And TextBox2.Text = "Captain123" Or
           TextBox1.Text = "13BonnN" And TextBox2.Text = "Captain123" Or
           TextBox1.Text = "13EarlJ" And TextBox2.Text = "Captain123" Or
           TextBox1.Text = "13RajaA" And TextBox2.Text = "Captain123" Or
           TextBox1.Text = "1" And TextBox2.Text = "1" Or
           TextBox1.Text = "13SchaJ" And TextBox2.Text = "Captain123" Then
            Timer1.Start() 'Timer on Form1.vb show
            ProgressBar1.Show() 'Progress bar on Form1.vb show
            Label8.Show() 'Label8 on Form1.vb show
            Button4.Show() 'Button4 on Form1.vb show
        Else
            cnt = cnt + 1
            If TextBox1.Text = "" And TextBox2.Text = "" Then
                MsgBox("No Username and/or Password Found!", MsgBoxStyle.Critical, "Error") 'If statement for checking if there is any input in either username or password entry field
            Else
                If TextBox1.Text = "" Then
                    MsgBox("No Username Found!", MsgBoxStyle.Critical, "Error") 'Message box no username found
                Else
                    If TextBox2.Text = "" Then
                        MsgBox("No Password Found!", MsgBoxStyle.Critical, "Error") 'Message box no password found
                    Else
                        MsgBox("Invalid Username And/Or Password!", MsgBoxStyle.Critical, "Error") 'Message box invlaid username and or password
                        TextBox2.Clear()
                    End If
                End If
            End If
        End If
    End If
End Sub`
于 2013-11-04T17:31:59.263 に答える