How to automatically login with VB Login form code?


Say username is ADMIN and password is ADMIN.
It should be auto LOGIN and it’s not showing FORM 3. What would the code be for Visual Basic. Is mine correct?

My form output:

Login form

Here’s my example code:

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If TextBox1.Text <> "" And TextBox2.Text <> "" Then
        MsgBox("Invalid username and password, Please try again!", +vbExclamation, +vbOK)


    ElseIf TextBox1.Text = My.Settings.Username And
    TextBox2.Text = My.Settings.Password Then
        MsgBox("Login Successfuly! Good day.", +vbInformation, +vbOK)
        Form3.Show()
        Me.Hide()

    Else
        MessageBox.Show("Please complete the required fields.", "Authentication Error" + TextBox1.Text + TextBox2.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)

    End If
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *