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

SQL Login Form with User Validation

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)
11 views2 pages

SQL Login Form with User Validation

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

LOGIN FORM

Imports [Link]
Imports [Link]

Public Class Form2


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

Try
[Link]()
' 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)
[Link]("@username", [Link])
[Link]("@password", [Link])

Dim count As Integer = Convert.ToInt32([Link]())


[Link]()

' Check credentials


If [Link]() = "admin" And [Link] = "0000" Then
[Link]("Welcome, Admin!", "Login Success", [Link],
[Link])
[Link]()
[Link]()
ElseIf count > 0 Then
[Link]("Welcome, User!", "Login Success", [Link],
[Link])
[Link]()
[Link]()
Else
[Link]("Invalid Username or Password", "Login Failed",
[Link], [Link])
End If

Catch ex As Exception
[Link]("Error: " & [Link], "Database Error", [Link],
[Link])
Finally
[Link]()
End Try
End Sub

' Show/Hide Password

1
Private Sub CheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles
[Link]
[Link] = Not [Link]
End Sub

' Redirect to Registration Form


Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs)
Handles [Link]
[Link]()
[Link]()

End Sub

Private Sub close_Click(sender As Object, e As EventArgs) Handles [Link]


[Link] = ""
[Link] = ""

End Sub
End Class

You might also like