Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "students" And TextBox2.Text = "amaer" Then
Dim a As New Form2
a.Show()
Me.Hide()
ElseIf MessageBox.Show("Please enter a valid Username and Password.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning) Then

End If
End Sub

Recommended Answers

All 3 Replies

Maybe you can try some thing like:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Static iPassCount as Integer ' thiss will assure that the counter is visible only locally but not lost from call to call
If TextBox1.Text = "students" And TextBox2.Text = "amaer" Then
Dim a As New Form2
a.Show()
iPassCount = 0 ' If passwor is ok then reset the counter
Me.Hide()
Else
iPassCount +=1 ' increase the counter
if iPassCount < 4 tehn ' while less than 3 retries notify the user
If MessageBox.Show("Please enter a valid Username and Password.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning) Then
End If
Else ' almost 3 times failed to enter the password
   ' Kill it?
End If
End If
End Sub

Hope this helps

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Try

If TextBox1.Text = "students" And TextBox2.Text = "amaer" Then
Dim a As New Form2
a.Show()
Me.Hide()

 Else

                'integer variable to count the number of times
                'the user has tried loggin in
                Static count As Integer = 0

                'display promt 
                Dim prompt As DialogResult = _
                MessageBox.Show("Invalid Username or Password!", "Login Error", _
                MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning)

                Select Case prompt

                    Case Windows.Forms.DialogResult.Retry
                        '//keep login displayed for another trial 
                        TextBox1.Text = ""
                        TextBox2.Text = ""

                        count += 1 'increment counter by one 
                        If count = 3 Then
                            MessageBox.Show("High value of failed login attempts" &              vbCrLf & _
                                           "Application will be terminated" & _
                                        " for security reasons", "Error", MessageBoxButtons.OK, _
                                        MessageBoxIcon.Stop)
                            End 'terminate application
                        End If

                    Case Windows.Forms.DialogResult.Cancel
                        Application.Exit()  'terminate application

                End Select

            End If
        Catch ex As Exception

        End Try

the code written should by me should totally solve your problem even more than you expected.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.