|
I have been using borrowed code to check a username and password against an access database before viewing a certain page. However, I needed to change the datatype in the access database from text to Number (integer) (for sorting purposes) and I don't know how to adjust the code to reflect the datatype change.
The username is actually a 4 digit number that is the person's membership number. (number datatype in access) The password is the persons zip code. (text type in access)
Info: logon2007.asp - has the logon box. logon2007.inc - has all the functions FanNumber = column of the database I am using as the username for the protected page (4 digit number) (Number datatype in access) Zip = column of the database I am using for the password (text datatype in access)
I don't know programming, but I THINK the problem might lie in the logon2007.inc file. So, that's the code I will give first:
logon2007.inc[size=3] --------------------
<% ' Do not cache this page. Response.CacheControl = "no-cache"
' Define the name of the users table. Const USERS_TABLE = "07Memberships" ' Define the path to the logon page. Const LOGON_PAGE = "/logon2007.asp" ' Define the path to the logon database. Const MDB_URL = "/fpdb/fanclubmembership.mdb"
' Check to see whether you have a current user name. If Len(Session("FanNumber")) = 0 Then ' Are you currently on the logon page? If LCase(LOGON_PAGE) <> LCase(Request.ServerVariables("URL")) Then ' If not, set a session variable for the page that made the request... Session("REFERRER") = Request.ServerVariables("URL") ' ...and redirect to the logon page. Response.Redirect LOGON_PAGE End If End If
' This function checks for a username/password combination. Function ComparePassword(FanNumber,Zip) ' Define your variables. Dim strSQL, objCN, objRS ' Set up your SQL string. strSQL = "SELECT * FROM " & USERS_TABLE & _ " WHERE (FanNumber='" & ParseText(FanNumber) & _ "' AND Zip='" & ParseText(Zip) & "');" ' Create a database connection object. Set objCN = Server.CreateObject("ADODB.Connection") ' Open the database connection object. objCN.Open "driver={Microsoft Access Driver (*.mdb)}; dbq=" & _ Server.MapPath(MDB_URL) & "; FanNumber=admin; Zip=" ' Run the database query. Set objRS = objCN.Execute(strSQL) ' Set the status to true/false for the database lookup. ComparePassword = Not(objRS.EOF) ' Close your database objects. Set objRS = Nothing Set objCN = Nothing End Function
' This function restricts text to alpha-numeric data only. Function ParseText(TXT) Dim intPos, strText, intText For intPos = 1 TO Len(TXT) intText = Asc(Mid(TXT,intPos,1)) If (intText > 47 And intText < 59) Or _ (intText > 64 And intText < 91) Or _ (intText > 96 And intText < 123) Then strText = strText & Mid(TXT,intPos,1) End if Next ParseText = strText End Function %>
------------------------
logon2007.asp[size=3] ------------------------
<% @language="vbscript" %> <!--#include virtual="/_private/logon2007.inc"-->
<% ' Was this page posted to? If UCase(Request.ServerVariables("HTTP_METHOD")) = "POST" Then ' If so, check the username/password that was entered. If ComparePassword(Request("FanNumber"),Request("Zip")) Then ' If comparison was good, store the user name... Session("FanNumber") = Request("FanNumber") ' ...and redirect back to the original page. Response.Redirect Session("REFERRER") End If End If %>
<form action="<%=LOGON_PAGE%>" method="POST"> <table border="0" cellpadding="2" bordercolorlight="#000000" bordercolordark="#000000" style="border-collapse: collapse"> <tr> <td><font face="Arial" size="2" color="#666666"> </font></td> <td align="left"> </td> <td align="left"><font face="Arial" size="2" color="#666666"><%=Request.ServerVariables("SERVER_NAME")%> </font></td> <td><font face="Arial" size="2" color="#666666"> </font></td> </tr> <tr> <td><font face="Arial" size="2" color="#666666"> </font></td> <td align="left"><font face="Arial" size="2" color="#666666">Fan Number </font></td> <td align="left"><font color="#666666" face="Arial"><input name="FanNumber" type="text" size="20"></font></td> <td><font face="Arial" size="2" color="#666666"> </font></td> </tr> <tr> <td><font face="Arial" size="2" color="#666666"> </font></td> <td align="left"><font face="Arial" size="2" color="#666666">Zip Code</font></td> <td align="left"><font color="#666666" face="Arial"><input name="Zip" type="password" size="20"></font></td> <td><font face="Arial" size="2" color="#666666"> </font></td> </tr> <tr> <td><font face="Arial" size="2" color="#666666"> </font></td> <td colspan="2" align="center"><font color="#666666" face="Arial"><input type="submit" value="LOGON"></font></td> <td><font face="Arial" size="2" color="#666666"> </font></td> </tr> </table> </form>
--------------------------
and finally the page that I want protected has the following at the start of the html:
<% @language="vbscript" %> <!--#include virtual="/_private/logon2007.inc"-->
This post has been edited by jdany: 2 Feb, 2007 - 07:29 AM
|