Database Connection/User Authentication
I've included the code for the .aspx page and for the code behind on the "Login" button.
Front end:
%@ Page Language="vb" AutoEventWireup="false" Codebehind="login.aspx.vb" Inherits="PIF_VB.login" %>
<HTML>
<HEAD>
<title>Login</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body bgColor="#cccccc" MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:textbox id="UserName" style="Z-INDEX: 101; LEFT: 200px; POSITION: absolute; TOP: 104px"
runat="server" Width="152px"></asp:textbox><asp:label id="Label1" style="Z-INDEX: 102; LEFT: 112px; POSITION: absolute; TOP: 112px" runat="server"
Width="82px" Font-Bold="True">User Name:</asp:label><asp:label id="Label2" style="Z-INDEX: 103; LEFT: 128px; POSITION: absolute; TOP: 152px" runat="server"
Width="64px" Font-Bold="True">Password:</asp:label><INPUT runat="server" style="Z-INDEX: 104; LEFT: 248px; POSITION: absolute; TOP: 184px"
type="submit" value="Login" id="Submit1" name="Submit1"><INPUT style="Z-INDEX: 105; LEFT: 200px; WIDTH: 152px; POSITION: absolute; TOP: 144px; HEIGHT: 24px"
type="password" size="20" id="password">
Backend on Login Button Click:
Private Sub Submit1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit1.ServerClick
Dim cn As New System.Data.SqlClient.SqlConnection("PROVIDER=SQLOLEDB;DATA SOURCE=themisto;UID=acadia_pif;PWD=pi32fs;DATABASE=AHOSP_PIF")
'here is where you will put the code to go after the login info
Try
'build a command from the connection
Dim cmd As New SqlClient.SqlCommand
cmd.Connection = cn
cmd.Parameters.Add("@username", System.Data.SqlDbType.Text, 80)
cmd.Parameters.Add("@password", System.Data.SqlDbType.Text, 80)
cmd.Parameters("@username").Value = UserName.Text
cmd.Parameters("@password").Value = password.Text
cmd.CommandText = "Select count(*) from AHOSP_Users where user_id=@username and password=@password"
'open the connection (execute scalar may do this for you)
cn.Open()
'return the number of records that match the credentials!
Dim cnt As Integer = cmd.ExecuteScalar
If cnt > 0 Then
'you found a match
'so go to the application pages!
'lblmsg.Text = "Congrats!"
'lblmsg.Visible = True
Response.Redirect("tab.aspx")
Else
'you didn't so give them a message
lblmsg.Text = "That username and password combination is not valid. Please try again."
lblmsg.Visible = True
End If
Catch ex As Exception
Finally
'be sure to dispose of the connection
cn.Dispose()
End Try
End Sub
End Class
If anyone can save my life, I'd truly appreciate it. Thanks!

