Problem with login/index scripts

J

John Meyer

index:
<%@ Page Language="VB" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Public strFullName As String

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Session("LoginNumber") Is Nothing Then
Response.Redirect("login.aspx")
Else
Dim strLoginQuery As String
strLoginQuery = "SELECT * FROM " & Session("TableType") & "
WHERE " & Session("PriKey") & "='" & Session("LoginNumber")
Dim conn As OleDbConnection
Dim comm As OleDbCommand
Dim dsRead As OleDbDataReader

Dim strConn As String
strConn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" &
"C:\Inetpub\wwwroot\Styles\db\styles2k3.mdb;"
conn = New OleDbConnection(strConn)
comm = New OleDbCommand(strLoginQuery, conn)
dsRead = comm.ExecuteReader(CommandBehavior.CloseConnection)
While dsRead.Read()
If Session("TableType") = "FACTORIES" Then
strFullName = dsRead("FACTORY_NAME")
Else
strFullName = dsRead(Session("Prefix") & "FNAME") &
" " & dsRead(Session("Prefix") & "LNAME")
End If
End While
dsRead.Close()


End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="StyleSheet" type="text/css" href="css/styles.css" />
<title>Welcome <%=strFullName%></title>
</head>
<body>
</body>
</html>


login:
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
Public strErrMessage As String

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim strLogin As String
Dim strPass As String

strLogin = Request.Form("txtLogin")
strPass = Request.Form("txtPassword")
If (strLogin <> "" And strPass <> "") Then
Dim strTable As String
Dim strTable2 As String
Dim strPrefix As String
Dim strPrefix2 As String
Dim strPrefix3 As String

strTable = ""
strTable2 = ""
strPrefix = ""
strPrefix2 = ""
strPrefix3 = ""
Select Case Request.Form("RadioButtonList1").ToString()
Case "Salesman"
strTable = "SALESLOGINS"
strTable2 = "SALESMEN"
strPrefix = "SL_"
strPrefix2 = "S_"
strPrefix3 = "SALESMAN_"
Case "Customer"
strTable = "CUSTLOGINS"
strTable2 = "CUSTOMERS"
strPrefix = "CL_"
strPrefix2 = "C_"
strPrefix3 = "CUSTOMER_"
Case "Supplier"
strTable = "FACTORYLOGINS"
strTable2 = "FACTORIES"
strPrefix = "FL_"
strPrefix2 = "F_"
strPrefix3 = "FACTORY_"
End Select
Dim conStr As String
Dim strQueryLogins As String
strQueryLogins = "SELECT TOP 1 FROM " & strTable & " WHERE "
& strPrefix & "LOGIN='" & strLogin & "' AND " & strPrefix & "PASSWORD='"
& strPass & "'"

conStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" &
"C:\Inetpub\wwwroot\Styles\db\styles2k3.mdb;"
Dim conn As OleDbConnection
Dim comm As OleDbCommand
Dim objReader As OleDbDataReader

conn = New OleDbConnection(conStr)
conn.Open()
comm = New OleDbCommand(strQueryLogins, conn)
objReader = comm.ExecuteReader(CommandBehavior.CloseConnection)
If objReader.HasRows() Then
While objReader.Read()
Session("LoginNumber") = objReader(strPrefix2 & "ID")
Session("PriKey") = strPrefix3 & "ID"
Session("TableType") = strTable2
Session("Prefix") = strPrefix3
End While
Response.Redirect("index.aspx")
Else
strErrMessage = "Error: invalid username/password, try
again"
End If
objReader.Close()

End If
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Login</title>
<link rel="StyleSheet" type="text/css" href="css/styles.css" />
</head>
<body>
<% If (Len(Trim(strErrMessage)) > 0) Then
Response.Write("<font color=red>" & strErrMessage & "</font>")
End If
%>
<h3>Login to website:</h3>
<form id="frmLogin" runat="server" action="login.aspx">
<div>
<asp:Label ID="Label1" runat="server" Text="User ID:"
Width="57px"></asp:Label>
<asp:TextBox ID="txtLogin" runat="server"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="Password:"
Width="56px"></asp:Label>
<input id="txtPassword" type="password" /><br />
<br />
Are you logging in as a:<br />
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Value="Customer"></asp:ListItem>
<asp:ListItem Value="Salesman"></asp:ListItem>
<asp:ListItem Value="Supplier"></asp:ListItem>
</asp:RadioButtonList><br />
<asp:Button ID="btnLogin" runat="server" Text="Login" />
<asp:Button ID="btnReset" runat="server" Text="Reset"
UseSubmitBehavior="False" /><br />

</div>
</form>
</body>
</html>

The index redirects fine on the first one, but when I login, it doesn't
seem to redirect me back to the right page (index.aspx)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top