Login form help

Havoc-X

New member
Joined
Aug 22, 2012
Messages
2
Programming Experience
Beginner
Hi all, i apologize if this is the wrong section, I'm new here.

I recently started learning Vb.net. I'm still pretty noob at it, anyway i'm having a problem with my log in form. Basically i'm trying to make a program where a user can log in and add stuff to a database (MS Access). The problem I'm having is related to trying to lock the user out after X amount of attempts.

This is my coding so far


VB.NET:
Public Class frmLogin

    Dim LoginAttempt As Integer = 0
    Dim strUserId As String
    Dim strPassword As String
    Dim currentRow As LoginDataSet.LoginRow
    Dim intCount As Integer
    Dim strCCName As String
    Dim blnAnswer As Boolean = False

VB.NET:
 Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        txtUserID.Focus()
        strUserId = Me.txtUserID.Text.ToUpper()

        For intCount = 0 To Me.LoginBindingSource.Count - 1
            currentRow = Me.LoginDataSet.Login.Item(intCount)
            If currentRow.UserID = strUserId Then
                If currentRow.AccountStatus = "Locked" Then
                    MessageBox.Show("This account has been locked due to suspicious activity. Please contact the administrator to unlock this account", "Account Locked", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation)
                    Me.Close()
                    Exit Sub
                End If
            Else
                Exit For
            End If
        Next

        If currentRow.UserID <> txtUserID.Text Then
            MessageBox.Show("User does not Exist")
            Me.txtUserID.Focus()
            Exit Sub
        End If


        txtUserID.Focus()
        strUserId = Me.txtUserID.Text.ToUpper()
        strPassword = Me.txtPassword.Text
        LoginAttempt = LoginAttempt + 1
        If LoginAttempt = 3 Then
            MessageBox.Show("You have entered an incorrect password 3 times. For security purposes, this account has now been locked. Please contact your administrator to unlock this account", "Account is now locked", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            For intCount = 0 To Me.LoginBindingSource.Count - 1
                currentRow = Me.LoginDataSet.Login.Item(intCount)
                If currentRow.UserID = strUserId Then
                    currentRow.AccountStatus = "Locked"
                    Exit For
                End If
            Next
            Me.Validate()
            Me.LoginBindingSource.EndEdit()
            Me.LoginTableAdapter.Update(Me.LoginDataSet.Login)
            Me.Close()
        Else
            For intCount = 0 To Me.LoginBindingSource.Count - 1
                currentRow = Me.LoginDataSet.Login.Item(intCount)
                If currentRow.UserID = strUserId And currentRow.Password = strPassword Then
                    blnAnswer = True
                    strCCName = currentRow.UserType
                    Me.Close()
                End If
            Next
        End If

        If blnAnswer = False And LoginAttempt < 3 Then
            MessageBox.Show("Incorrect User ID or Password has been used.", "Invalid Entry!", MessageBoxButtons.OKCancel, MessageBoxIcon.Error)
        End If

The part "if currentRow.AccountStatus = "Locked" .......

The program just seems to ignore this. (I have a status column in my database, it updates if i use a wrong password 3 times, but it's ignoring the "Locked" part. Therefore if i use the correct log - in, it works even with a "locked" account.

Again, i apologize if this is the wrong place / method i used to post this. Any help would be appreciated, thanks.
 
If currentRow.AccountStatus = "Locked" Then

Are you sure that both the database and this variable are updated? Is currentRow.AccountStatus definitely a String variable? Could it be amended outside this sub? I note that it's not declared on this form so are you sure that it has any value when this button click sub is reinitiated?
 
Hi, thanks for the reply, yes it is a string variable, The database is definitely being updated, not sure if the variable is. I declared them above as global variables in the log in form. Its possible I'm missing a line of code, it just simply bypasses that part.
 
Back
Top