VB.Net Login Form With MySQL

VB.NET - How To Create Login From With  MySQL DataBase Using Visual Basic.Net

Visual Basic.Net Login Form With DataBase

In This VB.Net Tutorial  We Will See How To Make A Login Window With MySQL Database 
In This Login Form We Will Add Two TextBox One For The Username And The Other For The Password, Add A CheckBox To Show And Hide Password Characters On CheckBox Checked Changed Event, Add Button Cancel To Close The Login Window,
Add Button Login To Search In MySQL DataBase If A User With This Username And Password Exists 
 - if the user exist hide this form and show a new form
 - if the user doesn't exist -> show a message
We Will Use MySqlCommand + MySqlDataAdapter + DataTable
Using Visual Basic.Net  Programming Language And Visual Studio Editor.


Part 1


Part 2


Project Source Code:

Imports MySql.Data.MySqlClient

Public Class Login_Form_With_MySQL

    Dim connection As New MySqlConnection("datasource=localhost;port=3306;username=root;password=;database=s_t_d")

    ' show/hide password text 
    Private Sub CheckBoxSP_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBoxSP.CheckedChanged

        If TextBoxPassword.UseSystemPasswordChar = True Then

            ' show password
            TextBoxPassword.UseSystemPasswordChar = False

        Else

            ' hide password
            TextBoxPassword.UseSystemPasswordChar = True

        End If

    End Sub

    ' button close form 
    Private Sub ButtonCancel_Click(sender As Object, e As EventArgs) Handles ButtonCancel.Click

        Me.Close()

    End Sub

    'button log in 
    Private Sub ButtonLogin_Click(sender As Object, e As EventArgs) Handles ButtonLogin.Click

        Dim command As New MySqlCommand("SELECT `Id`, `pass` FROM `user` WHERE `Id` = @username AND `pass` = @password", connection)

        command.Parameters.Add("@username", MySqlDbType.VarChar).Value = TextBoxUsername.Text
        command.Parameters.Add("@password", MySqlDbType.VarChar).Value = TextBoxPassword.Text

        Dim adapter As New MySqlDataAdapter(command)
        Dim table As New DataTable()

        adapter.Fill(table)

        If table.Rows.Count = 0 Then

            MessageBox.Show("Invalid Username Or Password")

        Else

            MessageBox.Show("Logged In")

            Dim newForm As New Insert_Update_Delete_Search()
            newForm.Show()
            Me.Hide()

        End If

    End Sub
End Class

///////////////OUTPUT:

VB.Net Login Form


login hide password


login display password


invalid username or password




Share this

Related Posts

Previous
Next Post »