0% found this document useful (0 votes)
9 views2 pages

Log Inform

The document is a code snippet for a login form in a Windows Forms application using VB.NET. It establishes a connection to a SQL Server database to validate user credentials and provides feedback based on the login attempt. Additionally, it includes functionality for showing/hiding the password and redirecting to a registration form.

Uploaded by

rb0374
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Log Inform

The document is a code snippet for a login form in a Windows Forms application using VB.NET. It establishes a connection to a SQL Server database to validate user credentials and provides feedback based on the login attempt. Additionally, it includes functionality for showing/hiding the password and redirecting to a registration form.

Uploaded by

rb0374
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

LOGIN FORM

Imports System.Data.SqlClient
Imports System.Windows.Forms.VisualStyles.VisualStyleElement

Public Class Form2


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Database Connection String
Dim con As New SqlConnection("Data Source=RB-REALME\SQLEXPRESS03;Initial
Catalog=starlight;Integrated Security=True;TrustServerCertificate=True")

Try
con.Open()
' Query to check if the username exists
Dim query As String = "SELECT COUNT(*) FROM [user info] WHERE
username=@username AND password=@password"
Dim cmd As New SqlCommand(query, con)
cmd.Parameters.AddWithValue("@username", txtuser.Text)
cmd.Parameters.AddWithValue("@password", txtpass.Text)

Dim count As Integer = Convert.ToInt32(cmd.ExecuteScalar())


con.Close()

' Check credentials


If txtuser.Text.ToLower() = "admin" And txtpass.Text = "0000" Then
MessageBox.Show("Welcome, Admin!", "Login Success", MessageBoxButtons.OK,
MessageBoxIcon.Information)
adimnpage.Show()
Me.Hide()
ElseIf count > 0 Then
MessageBox.Show("Welcome, User!", "Login Success", MessageBoxButtons.OK,
MessageBoxIcon.Information)
bookings.Show()
Me.Hide()
Else
MessageBox.Show("Invalid Username or Password", "Login Failed",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

Catch ex As Exception
MessageBox.Show("Error: " & ex.Message, "Database Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Finally
con.Close()
End Try
End Sub

' Show/Hide Password

1
Private Sub CheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox.CheckedChanged
txtpass.UseSystemPasswordChar = Not CheckBox.Checked
End Sub

' Redirect to Registration Form


Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs)
Handles LinkLabel1.LinkClicked
Form1.Show()
Me.Hide()

End Sub

Private Sub close_Click(sender As Object, e As EventArgs) Handles close.Click


txtuser.Text = ""
txtpass.Text = ""

End Sub
End Class

You might also like