LOGIN Problems

liam

Member
Joined
Jun 8, 2004
Messages
23
Programming Experience
Beginner
how can i count the number of failed logins?
where do i put the code..
thanks...
Private Sub btnSOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSOk.Click

If lblPassword.Text = tbPassWord.Text Then

m.logged = True

m.Show()

Else

Dim ctr As Integer

m.logged = False

MsgBox("Invalid Username or Password! Try Again?", MsgBoxStyle.YesNo)

If MsgBoxResult.Yes Then

tbPassWord.Text = ""

ctr = ctr + 1

lblctr.Text = ctr

Me.Show()

Else

m.Close()

End If

End If

 

mzim

Well-known member
Joined
Jun 3, 2004
Messages
187
Location
Other side of the rock
Programming Experience
1-3
this one?
i put in keydown event of my textbox
it depends on you on where you put this or just put it in button click event
VB.NET:
dim i as integer
 Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
  		If e.KeyCode = Keys.Enter Then
  			If TextBox1.Text = "mzim" Then
  			Else
 			 If MessageBox.Show("invalid user", "note", MessageBoxButtons.OK) = DialogResult.OK Then
  					i += 1
  				    TextBox1.Text = ""
  				    TextBox1.Focus()
 					If i = 4 Then
 					 MessageBox.Show("no. of failed log-in ", "note" & i)
 					 Exit Sub
  					End If
  				End If
  			End If
  		End If
  	End Sub

hope this helps
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
I'll explain what mzim has done.

The problem with your code was the scope of the ctr variable. In your code, ctr has a procedure scope. This means that the variable only exists while the procedure is executing and is recreated (and destroyed) each time the procedure is executed. In mzim's code, the variable has class scope, which means the variable is created when the class is created (a form is a class) and remains in memory until the class is disposed.
 
Top Bottom