Imports System.Data.OleDb
Imports System.Data
Partial Class Login_Login
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If (txtUsername.Text = "") Or (txtPassword.Text = "") Then
Me.lblMsg.Text = "Invalid Username & Password"
End If
Dim objConn As New OleDbConnection("Provider=SQLOLEDB;Data Source=DELL_BLUE-PC;Integrated Security=SSPI;Initial Catalog=UTCCResearch")
With objConn
If .State = ConnectionState.Open Then .Close()
.Open()
End With
Dim da As New OleDbDataAdapter("SELECT * FROM admin WHERE (Username = '" + txtUsername.Text & "') AND (Password = '" + txtPassword.Text & "') ", objConn)
Dim ds As New DataSet()
da.Fill(ds, "admin")
If ds.Tables("admin").Rows.Count = 0 Then
Me.lblMsg.Text = "Invalid Username & Password"
Else
Response.Redirect("testSQL.aspx")
End If
End Sub
End Class
Imports System.Data.SqlClient
Partial Class LoginForm
Inherits System.Web.UI.Page
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If IsUser() Then
Response.Redirect("testSQL.aspx")
Else
MessageBox("Invalid Username & Password", "LoginFail")
End If
End Sub
Protected Function IsUser() As Boolean
Dim HaveUser As Boolean = False
Dim user As Integer = 0
Dim connectionString As String = "Data Source=DELL_BLUE-PC;Initial Catalog=UTCCResearch;Integrated Security=SSPI;"
Dim objConnection As New SqlConnection(connectionString)
Dim commandString As String = "Select Count(*) From [admin] Where [Username]=@Username And [Password]=@Password"
Dim objCommand As New SqlCommand(commandString, objConnection)
objCommand.Parameters.AddWithValue("@Username", txtUsername.Text)
objCommand.Parameters.AddWithValue("@Password", txtPassword.Text)
Try
objConnection.Open()
user = CInt(objCommand.ExecuteScalar())
objCommand.Clone()
If user > 0 Then
HaveUser = True
End If
Catch ex As Exception
MessageBox(String.Format("Error: {0}", ex.Message), "ErrorMessage")
Exit Try
End Try
Return HaveUser
End Function
Protected Sub MessageBox(ByVal Message As String, ByVal MessageName As String)
Dim ClientScript As ClientScriptManager = Page.ClientScript
If Not ClientScript.IsClientScriptBlockRegistered(Me.GetType(), MessageName) Then
ClientScript.RegisterClientScriptBlock(Me.GetType(), MessageName, String.Format("alert('{0}')", Message), True)
End If
End Sub
End Class
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If IsUser() Then
Response.Redirect("testSQL.aspx")
Else
MessageBox("Invalid Username & Password", "LoginFail")
End If
End Sub