VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Simple login form for a Windows application that checks the entered username and password against a

by myshadow (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Originally Published: Thu 25th December 2008
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Simple login form for a Windows application that checks the entered username and password against a list of usernames and passwords in a

API Declarations


' You must do the following for this to work:
' 1 - create a Windows Forms Application named "TryLoggingIn"
' 2 - create a login form.
' a - right click project name in solution explorer
' add|New Item|Login Form
' b- double click on empty portion of the form. Insert this code.
' 3 - rename Form1 to MainMenu
' 4 - Project|Properties on Application tab
' a- change shutdown mode to "when last form closes"
' b- change the startup form to LoginForm1
' 5 - Connect the database to the project. The database I attached (users.sdf)
' has a table named tblEmployees:
' Primary Key = UserID, int, no nulls, identity = true
' EmpLast mvarchar(30)
' EmpFirst mvarchar (30)
' EmpUserName, mvarchar (35), no nulls, must be unique
' EmpPassword, mvarchar (35), no nulls
' **** Remember to change the database's "Copy to Output" property to "Copy if Newer'
' 6 - create a query to select a specific EmpUserName
' a- double click on the dataset in the Solution Explorer Window to
' open the dataset explorer
' NOTE: you may have to drag the table from the Database Explorer to the
' dataset explorer.
' b- right click on "fill, GetData()" in the tableadapter section of the
' table you are going to add the query
' c- select "Add Query" -- wizard comes up
' d- select "Use SQL Statements", click "Next"
' e- select "SELECT which returns rows", click "Next"
' f- you will see a select table. click on "Query Builder"
' g- scroll down to EmpUserName. In the "filter" column, type: =@UserName
' h- click off the EmpUserName row. this will put a WHERE clause in your query.
' i- click 'OK'
' j- click 'Finish'. This will add a "GetDataBy" method, that uses a parameter

Rate Simple login form for a Windows application that checks the entered username and password against a





    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

        ' Validate the Username and Password Provided in the textboxes
        If validUsernamePassword(UsernameTextBox.Text, PasswordTextBox.Text) Then
            'Valid username/password!  Let them into the Main Menu
            Dim myMainMenu As New MainMenu
            myMainMenu.Show()

            ' close the login form.
            Me.Close()
        Else
            'We have invalid username/password.  
            ' put up error box
            MsgBox("Invalid Username or Password. Try Again.", MsgBoxStyle.Critical, "Error")

            ' clear the text boxes, to let them try again
            UsernameTextBox.Text = ""
            PasswordTextBox.Text = ""
        End If

    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub

    Private Function validUsernamePassword(ByVal argUsername As String, ByVal argPassword As String) As Boolean

        'check for null password
        If Trim(argUsername) = "" Then
            validUsernamePassword = False
            Exit Function
        End If

        'check for null password
        If Trim(argPassword) = "" Then
            validUsernamePassword = False
            Exit Function
        End If

        'get an employee table where the username is equal to the entered username
        Dim employeeTable As TryLoggingIn.usersDataSet.tblEmployeeDataTable
        employeeTable = TblEmployeeTableAdapter1.GetDataBy(Trim(argUsername))

        'if we got a record (and only one record), then check the password
        If employeeTable.Count = 1 Then
            If employeeTable(0).EmpPassword = Trim(argPassword) Then
                validUsernamePassword = True
                Exit Function
            End If
        End If

        ' didn't have a valid username password
        validUsernamePassword = False

    End Function

End Class

Download this snippet    Add to My Saved Code

Simple login form for a Windows application that checks the entered username and password against a Comments

No comments have been posted about Simple login form for a Windows application that checks the entered username and password against a. Why not be the first to post a comment about Simple login form for a Windows application that checks the entered username and password against a.

Post your comment

Subject:
Message:
0/1000 characters