I have already create a login code and form. but now, i would like to do some improvement in my login by doing some extreme login. so everytime the users put invalid username or password for let say three times, the system will quit and starts from the beginning again. any idea on how to do this?
thanks before!!
here my code :
Public Class frmLogin
Private Sub CmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdCancel.Click
Dim hasil As MsgBoxResult
hasil = MessageBox.Show("Are you sure want to exit from this system ?", "Exit system", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If hasil = MsgBoxResult.Yes Then
End
Else
txtUsername.Focus()
End If
End Sub
Private Sub frmLogin_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
txtUsername.Clear()
txtPassword.Clear()
txtUsername.Focus()
End Sub
Private Sub txtUsername_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUsername.KeyPress
If Asc(e.KeyChar) = 13 Then
txtUsername.Focus()
End If
End Sub
Private Sub txtPassword_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPassword.KeyPress
If Asc(e.KeyChar) = 13 Then
CmdOk.PerformClick()
End If
End Sub
Private Sub CmdOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdOk.Click
Dim fmCashier As New frmCashier
Dim fmMDI As New frmMDI
Dim Sql$
Dim strs As String = ""
Dim pwd As String = ""
Dim com As New SqlClient.SqlCommand
Dim reader As SqlClient.SqlDataReader = Nothing
If txtUsername.Text.Trim = "" Then
MessageBox.Show("Please enter the Username", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtUsername.Focus()
Exit Sub
End If
If txtPassword.Text.Trim = "" Then
Call MessageBox.Show("Please enter the Password", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtPassword.Focus()
Exit Sub
End If
Sql = "SELECT * FROM " & TBLUSERNAME
Sql = Sql & " WHERE USERNAME='" & txtUsername.Text.Trim & "'"
Call ExecuteReader(gconUser, reader, Sql)
If reader.HasRows Then
If CStr(reader("PASSWORD")) = CStr(txtPassword.Text) Then
If OpManager.Checked Then
If UCase(reader("USERROLE")) = "MANAGER" Then
MessageBox.Show(UCase(strs) & " Welcome to the System", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information)
fmMDI.Show()
Me.Close()
Else
MessageBox.Show("You are not authorized to login as Manager", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtUsername.Focus()
GoTo quit
End If
Else
MessageBox.Show(UCase(strs) & " Welcome to the System", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information)
fmCashier.Show()
fmCashier.BtnUser.Text = txtUsername.Text
Me.Close()
End If
Else
MessageBox.Show("Invalid Password,Please try again", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtPassword.Clear()
txtPassword.Focus()
reader.Close()
End If
Else
MessageBox.Show("No such user in system, Please contact the administrator", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtUsername.Clear()
txtPassword.Clear()
txtUsername.Focus()
End If
quit:
reader.Close()
End Sub
End Class
any help from all of you will be great!!
This post has been edited by rob2y_k: 19 November 2009 - 03:45 AM

New Topic/Question
Reply




MultiQuote




|