This is a multi-part message in MIME format.

------=_NextPart_000_0026_01C45737.68254FB0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Applies to: Microsoft FrontPage 2000, Microsoft Access 2000, IIS 5.0
Operating System: Microsoft Windows 2000 Professional

I am trying to protect a portion of a web site by allowing users to =
register a username and password & then login with those details, but so =
far I am having only marginal success. I am far from an expert on ASP =
programming, indeed the code I am using comes from "Sams Teach Yourself =
E-Commerce Programming with ASP" but it is ideally suited for my =
purpose.

In short, there are 3 .asp pages (register.asp, login.asp & =
checkpassword.asp - the code for each is below), a global.asa file was =
automatically created and by following the instructions in the book, I =
also created a small Access database called UserDB.mdb, which stores the =
username & password of each user when they register & also verify's =
those details when the user attempts to login again.

The DNS connection has been setup within FrontPage and I have verified =
that this connection works by clicking "Tools", "Web Settings" & the =
"Database" tab, highlighting the DNS connection & clicking Verify.=20

The problems seem to occur when I try to register a new username & =
password, for some strange reason the details I enter are not being =
saved in the database table, and to compound the problem further, if I =
register just a username, or a password but not both, the page simply =
refreshes itself with empty boxes instead of giving an error message to =
indicate that a "username" or "password" must be entered, which if I =
have read the code correctly on the "checkpassword.asp" page, should =
happen.

To further confuse the situation, if I manually enter a username & =
password into the database table and then attempt to click a hyperlink =
taking me to a "test.asp" page, with the INCLUDE FILE: <!-- #INCLUDE =
FILE=3D"checkpassword.asp" -->, I am automatically taken to the =
login.asp, where if I enter the username & password that I manually put =
into the database table, it takes me to the selected "Protected" web =
page. In my mind that clearly shows the DNS connection is working but =
yet it won't store new registered details into the database table, which =
is extremely confusing.

If anyone can see what I may be doing wrong, or point me in the right =
direction, your help & advice will be greatly appreciated. As I pointed =
out earlier I am far from an expert, so any help you can give would be =
ideally suited towards a newbie mentality.

Below is the code for the three .asp pages:

Many thanks in advance
Wayne Smith



register.asp

<%
nextPage =3D Request( "nextPage" )

newUsername =3D Request( "newUsername" )

newPassword =3D Request( "newPassword" )

%>

<HTML>

<HEAD><TITLE>Register"</TITLE></HEAD>

<BODY>

Register at this Web site by selecting a username and password:

<FORM METHOD=3D"post" ACTION=3D"<%=3DnextPage%>">

<INPUT NAME=3D"newUser" TYPE=3D"hidden" VALUE=3D"1">

<P><B>USERNAME:</B>

<INPUT NAME=3D"newUsername" SIZE=3D20 MAXLENGTH=3D"20"=20

VALUE=3D"<%=3DServer.HTMLEncode( newUsername )%>">

<P><B>PASSWORD:</B>

<INPUT NAME=3D"newPassword" SIZE=3D20 MAXLENGTH=3D"20"=20

VALUE=3D"<%=3DServer.HTMLEncode( newPassword )%>">

<P><INPUT TYPE=3D"submit" VALUE=3D"Register!">

</FORM>

</BODY>

</HTML>

-------------------------------------------------------------------------=
---------

login.asp

<HTML>

<HEAD><TITLE>Login</TITLE></HEAD>

<BODY>

<%=3DloginMessage%>

<FORM METHOD=3D"post" ACTION=3D"<%=3DnextPage%>">

<P><B>USERNAME:</B>

<INPUT NAME=3D"username" SIZE=3D20 MAXLENGTH=3D"20"=20

VALUE=3D"<%=3DServer.HTMLEncode( username )%>">

<P><B>PASSWORD:</B>

<INPUT NAME=3D"password" SIZE=3D20 MAXLENGTH=3D"20"=20

VALUE=3D"<%=3DServer.HTMLEncode( password )%>">

<p><INPUT NAME=3D"addCookie" TYPE=3D"Checkbox" VALUE=3D"1"> Remember me =
with a cookie

<P><INPUT TYPE=3D"submit" VALUE=3D"Login">

</FORM>

<p>

<a href=3D"register.asp?nextpage=3D<%Server.URLEncode( nextpage )%>">

Click here to register</a>

</BODY>

</HTML>

-------------------------------------------------------------

checkpassword.asp

<%

CONST useSession =3D TRUE

' Retrieve Form Variables

username =3D TRIM( Request( "username" ) )

password =3D TRIM( Request( "password" ) )

newUser =3D TRIM( Request( "newUser" ) )

newUsername =3D TRIM( Request( "newUsername" ) )

newPassword =3D TRIM( Request( "newPassword" ) )

addCookie =3D TRIM( Request( "addCookie" ) )

' Retrieve Current Page

nextPage =3D Request.ServerVariables( "SCRIPT_NAME" )

' Ready Database Connection

Set Con =3D Server.CreateObject( "ADODB.Connection" )

Con.Open "userDNS"

' Add New User

IF newUser <> "" THEN

IF newUsername =3D "" THEN

showError "You must enter a username"

END IF

IF newPassword =3D "" THEN

showError "You must enter a password"

END IF

IF usernameTaken( newUsername ) THEN

showError "The username you entered has already " &_

"been chosen by a previous user. Please select " &_

"a new username"

END IF

sqlString =3D "INSERT INTO userlist ( user_username, user_password ) " =
&_

"VALUES ('" & newUsername & "','" & newPassword & "')"

Con.Execute sqlString

username =3D newUsername

password =3D newPassword

IF useSession THEN Session( "loggedIn" ) =3D "Yes"

END IF

' Authenticate User

IF Session( "loggedIn" ) =3D "" THEN=20

IF username =3D "" OR password =3D "" THEN

loginMessage =3D "You must login before you can view this page."

showLogin

END IF

result =3D validateLogin( username, password )

IF result =3D 1 THEN

loginMessage =3D "You entered an unregistered username."

showLogin

END IF

IF result =3D 2 THEN

loginMessage =3D "You did not enter a valid password."

showLogin

END IF

IF useSession THEN Session( "loggedIn" ) =3D "Yes"

END IF

' Add a Cookie

IF addCookie <> "" THEN

Response.Cookies( "username" ) =3D username

Response.Cookies( "username" ).Expires =3D "12/25/2037"

Response.Cookies( "password" ) =3D password

Response.Cookies( "password" ).Expires =3D "12/25/2037"

END IF

' Create Security Query String Variable

sq =3D "username=3D" & Server.HTMLEncode( username ) & "&"

sq =3D sq & "password=3D" & Server.HTMLEncode( password )=20

' Create Security Form Variable

sf =3D "<input name=3D""username"" type=3D""hidden"" "

sf =3D sf & "value=3D""" & Server.HTMLEncode( username ) & """>"

sf =3D sf & "<input name=3D""password"" type=3D""hidden"" "

sf =3D sf & "value=3D""" & Server.HTMLEncode( password ) & """>"

' Check Username and Password

FUNCTION validateLogin( theUsername, thePassword )

sqlString =3D "SELECT user_password FROM userlist " &_

"WHERE user_username=3D'" & fixQuotes( username ) & "'"=20

Set RS =3D Con.Execute( sqlString )

IF RS.EOF THEN

validateLogin =3D 1

ELSE

IF RS( "user_password" ) <> thePassword THEN

validateLogin =3D 2

ELSE

validateLogin =3D 0

END IF

END IF

END FUNCTION



' Check Whether Username Already Taken

FUNCTION usernameTaken( theUsername )

sqlString =3D "SELECT user_id FROM userlist " &_

"WHERE user_username=3D'" & fixQuotes( theUsername ) & "'"

Set RS =3D Con.Execute( sqlString )

IF RS.EOF THEN

usernameTaken =3D FALSE

ELSE

usernameTaken =3D TRUE

END IF

RS.Close

Set RS =3D Nothing

END FUNCTION

' Show Error Page

SUB showError( theError )

%>

<HTML>

<HEAD><TITLE>Problem</TITLE></HEAD>

<BODY>

<b>There was a problem with your registration information</b>

<br><%=3DtheError %>

<FORM METHOD=3D"POST" ACTION=3D"register.asp">

<INPUT NAME=3D"nextpage" TYPE=3D"hidden"

VALUE=3D"<%=3Dnextpage%>">

<INPUT NAME=3D"newUsername" TYPE=3D"hidden"

VALUE=3D"<%=3DServer.HTMLEncode( newUsername )%>">

<INPUT NAME=3D"newPassword" TYPE=3D"hidden"

VALUE=3D"<%=3DServer.HTMLEncode( newPassword )%>">

<INPUT TYPE=3D"SUBMIT" VALUE=3D"Continue">

</FORM>

</BODY>

</HTML>

<%

Response.End

END SUB

' Show the Login Page

SUB showLogin

%>

<!-- #INCLUDE FILE=3D"login.asp" -->

<%

Response.End

END SUB

FUNCTION fixQuotes( theString )

fixQuotes =3D REPLACE( theString, "'", "''" )

END FUNCTION

%>

------=_NextPart_000_0026_01C45737.68254FB0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1400" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D1>
<DIV><FONT size=3D2>Applies to: Microsoft FrontPage 2000, Microsoft =
Access 2000,=20
IIS 5.0</FONT></DIV>
<DIV><FONT size=3D2>Operating System: Microsoft Windows 2000=20
Professional</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>I am trying to protect a portion of a web site by =
allowing=20
users to register a username and password &amp; then login with those =
details,=20
but so far I am having only marginal success. I am far from an expert on =
ASP=20
programming, indeed the code I am using comes from "Sams Teach Yourself=20
E-Commerce Programming with ASP" but it is ideally suited for my=20
purpose.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>In short, there are 3 .asp pages (register.asp, =
login.asp=20
&amp; checkpassword.asp - the code for each is below), a global.asa file =
was=20
automatically created and by following the instructions in the book, I =
also=20
created a small Access database called UserDB.mdb, which stores the =
username=20
&amp; password of each user when they register &amp; also verify's those =
details=20
when the user attempts to login again.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>The DNS connection has been setup within FrontPage =
and I have=20
verified that this connection works by clicking "Tools", "Web Settings" =
&amp;=20
the "Database" tab, highlighting the DNS connection &amp; clicking =
Verify.=20
</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>The problems seem to occur when I try to register a =
new=20
username &amp; password, for some strange reason the details I enter are =
not=20
being saved in the database table, and to compound the problem further, =
if I=20
register just a username, or a password but not both, the page simply =
refreshes=20
itself with empty boxes instead of giving an error message to indicate =
that a=20
"username" or "password" must be entered, which if I have read the code=20
correctly on the "checkpassword.asp" page, should happen.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>To further confuse the situation, if I manually =
enter a=20
username &amp; password into the database table and then attempt to =
click a=20
hyperlink taking me to a "test.asp" page, with the INCLUDE FILE: &lt;!-- =

#INCLUDE FILE=3D"checkpassword.asp" --&gt;, I am automatically taken to =
the=20
login.asp, where if I enter the username &amp; password that I manually =
put into=20
the database table, it takes me to the selected "Protected" web page. In =
my mind=20
that clearly shows the DNS connection is working but yet it won't store =
new=20
registered details into the database table, which is extremely=20
confusing.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>If anyone can see what I may be doing wrong, or =
point me in=20
the right direction, your help &amp; advice will be greatly appreciated. =
As I=20
pointed out earlier I am far from an expert, so any help you can give =
would be=20
ideally suited towards a newbie mentality.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Below is the code for the three .asp =
pages:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Many thanks in advance</FONT></DIV>
<DIV><FONT size=3D2>Wayne Smith</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>register.asp</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#800000><FONT size=3D2>&lt;%</FONT></DIV>
<DIV>
<P><FONT size=3D2>nextPage =3D Request( "nextPage" )</FONT></P>
<P><FONT size=3D2>newUsername =3D Request( "newUsername" )</FONT></P>
<P><FONT size=3D2>newPassword =3D Request( "newPassword" )</FONT></P>
<P><FONT size=3D2>%&gt;</FONT></P></FONT><FONT color=3D#0000c0>
<P><FONT size=3D2>&lt;HTML&gt;</FONT></P>
<P><FONT size=3D2>&lt;HEAD&gt;&lt;TITLE&gt;</FONT></FONT><FONT=20
size=3D2>Register"</FONT><FONT color=3D#0000c0><FONT=20
size=3D2>&lt;/TITLE&gt;&lt;/HEAD&gt;</FONT></P>
<P><FONT size=3D2>&lt;BODY&gt;</FONT></P></FONT>
<P><FONT size=3D2>Register at this Web site by selecting a username and=20
password:</FONT></P><FONT color=3D#0000c0>
<P><FONT size=3D2>&lt;FORM METHOD=3D</FONT></FONT><FONT =
size=3D2>"post"<FONT=20
color=3D#0000c0> ACTION=3D</FONT>"<FONT=20
color=3D#800000>&lt;%=3DnextPage%&gt;</FONT>"</FONT><FONT =
color=3D#0000c0><FONT=20
size=3D2>&gt;</FONT></P>
<P><FONT size=3D2>&lt;INPUT NAME=3D</FONT></FONT><FONT =
size=3D2>"newUser"<FONT=20
color=3D#0000c0> TYPE=3D</FONT>"hidden"<FONT color=3D#0000c0>=20
VALUE=3D</FONT>"1"</FONT><FONT color=3D#0000c0><FONT =
size=3D2>&gt;</FONT></P>
<P><FONT size=3D2>&lt;P&gt;&lt;B&gt;</FONT></FONT><FONT=20
size=3D2>USERNAME:</FONT><FONT color=3D#0000c0><FONT =
size=3D2>&lt;/B&gt;</FONT></P>
<P><FONT size=3D2>&lt;INPUT NAME=3D</FONT></FONT><FONT =
size=3D2>"newUsername"<FONT=20
color=3D#0000c0> SIZE=3D</FONT>20<FONT color=3D#0000c0>=20
MAXLENGTH=3D</FONT>"20"</FONT><FONT color=3D#0000c0><FONT size=3D2> =
</FONT></P>
<P><FONT size=3D2>VALUE=3D</FONT></FONT><FONT size=3D2>"<FONT=20
color=3D#800000>&lt;%=3DServer.HTMLEncode( newUsername =
)%&gt;</FONT>"</FONT><FONT=20
color=3D#0000c0><FONT size=3D2>&gt;</FONT></P>
<P><FONT size=3D2>&lt;P&gt;&lt;B&gt;</FONT></FONT><FONT=20
size=3D2>PASSWORD:</FONT><FONT color=3D#0000c0><FONT =
size=3D2>&lt;/B&gt;</FONT></P>
<P><FONT size=3D2>&lt;INPUT NAME=3D</FONT></FONT><FONT =
size=3D2>"newPassword"<FONT=20
color=3D#0000c0> SIZE=3D</FONT>20<FONT color=3D#0000c0>=20
MAXLENGTH=3D</FONT>"20"</FONT><FONT color=3D#0000c0><FONT size=3D2> =
</FONT></P>
<P><FONT size=3D2>VALUE=3D</FONT></FONT><FONT size=3D2>"<FONT=20
color=3D#800000>&lt;%=3DServer.HTMLEncode( newPassword =
)%&gt;</FONT>"</FONT><FONT=20
color=3D#0000c0><FONT size=3D2>&gt;</FONT></P>
<P><FONT size=3D2>&lt;P&gt;&lt;INPUT TYPE=3D</FONT></FONT><FONT =
size=3D2>"submit"<FONT=20
color=3D#0000c0> VALUE=3D</FONT>"Register!"</FONT><FONT =
color=3D#0000c0><FONT=20
size=3D2>&gt;</FONT></P>
<P><FONT size=3D2>&lt;/FORM&gt;</FONT></P></FONT><FONT color=3D#0000c0>
<P><FONT size=3D2>&lt;/BODY&gt;</FONT></P>
<P><FONT size=3D2>&lt;/HTML&gt;</FONT></P>
<P><FONT=20
size=3D2>----------------------------------------------------------------=
------------------</FONT></P>
<P></FONT><FONT size=3D2>login.asp</FONT></P>
<P><FONT color=3D#0000c0 size=3D1><FONT =
size=3D2>&lt;HTML&gt;</FONT></P></DIV>
<DIV>
<P><FONT size=3D2>&lt;HEAD&gt;&lt;TITLE&gt;</FONT></FONT><FONT=20
size=3D2>Login</FONT><FONT color=3D#0000c0><FONT=20
size=3D2>&lt;/TITLE&gt;&lt;/HEAD&gt;</FONT></P>
<P><FONT size=3D2>&lt;BODY&gt;</FONT></P></FONT><FONT color=3D#800000 =
size=3D2>
<P>&lt;%=3DloginMessage%&gt;</P></FONT><FONT color=3D#0000c0>
<P><FONT size=3D2>&lt;FORM METHOD=3D</FONT></FONT><FONT =
size=3D2>"post"<FONT=20
color=3D#0000c0> ACTION=3D</FONT>"<FONT=20
color=3D#800000>&lt;%=3DnextPage%&gt;</FONT>"</FONT><FONT =
color=3D#0000c0><FONT=20
size=3D2>&gt;</FONT></P>
<P><FONT size=3D2>&lt;P&gt;&lt;B&gt;</FONT></FONT><FONT=20
size=3D2>USERNAME:</FONT><FONT color=3D#0000c0><FONT =
size=3D2>&lt;/B&gt;</FONT></P>
<P><FONT size=3D2>&lt;INPUT NAME=3D</FONT></FONT><FONT =
size=3D2>"username"<FONT=20
color=3D#0000c0> SIZE=3D</FONT>20<FONT color=3D#0000c0>=20
MAXLENGTH=3D</FONT>"20"</FONT><FONT color=3D#0000c0><FONT size=3D2> =
</FONT></P>
<P><FONT size=3D2>VALUE=3D</FONT></FONT><FONT size=3D2>"<FONT=20
color=3D#800000>&lt;%=3DServer.HTMLEncode( username =
)%&gt;</FONT>"</FONT><FONT=20
color=3D#0000c0><FONT size=3D2>&gt;</FONT></P>
<P><FONT size=3D2>&lt;P&gt;&lt;B&gt;</FONT></FONT><FONT=20
size=3D2>PASSWORD:</FONT><FONT color=3D#0000c0><FONT =
size=3D2>&lt;/B&gt;</FONT></P>
<P><FONT size=3D2>&lt;INPUT NAME=3D</FONT></FONT><FONT =
size=3D2>"password"<FONT=20
color=3D#0000c0> SIZE=3D</FONT>20<FONT color=3D#0000c0>=20
MAXLENGTH=3D</FONT>"20"</FONT><FONT color=3D#0000c0><FONT size=3D2> =
</FONT></P>
<P><FONT size=3D2>VALUE=3D</FONT></FONT><FONT size=3D2>"<FONT=20
color=3D#800000>&lt;%=3DServer.HTMLEncode( password =
)%&gt;</FONT>"</FONT><FONT=20
color=3D#0000c0><FONT size=3D2>&gt;</FONT></P>
<P><FONT size=3D2>&lt;p&gt;&lt;INPUT NAME=3D</FONT></FONT><FONT=20
size=3D2>"addCookie"<FONT color=3D#0000c0> TYPE=3D</FONT>"Checkbox"<FONT =

color=3D#0000c0> VALUE=3D</FONT>"1"<FONT color=3D#0000c0>&gt;</FONT> =
Remember me with=20
a cookie</FONT></P><FONT color=3D#0000c0>
<P><FONT size=3D2>&lt;P&gt;&lt;INPUT TYPE=3D</FONT></FONT><FONT =
size=3D2>"submit"<FONT=20
color=3D#0000c0> VALUE=3D</FONT>"Login"</FONT><FONT =
color=3D#0000c0><FONT=20
size=3D2>&gt;</FONT></P>
<P><FONT size=3D2>&lt;/FORM&gt;</FONT></P>
<P><FONT size=3D2>&lt;p&gt;</FONT></P>
<P><FONT size=3D2>&lt;a href=3D</FONT></FONT><FONT=20
size=3D2>"register.asp?nextpage=3D<FONT =
color=3D#800000>&lt;%Server.URLEncode(=20
nextpage )%&gt;</FONT>"<FONT color=3D#0000c0>&gt;</P></FONT></FONT>
<P><FONT size=3D2>Click here to register<FONT=20
color=3D#0000c0>&lt;/a&gt;</P></FONT></FONT><FONT color=3D#0000c0>
<P><FONT size=3D2>&lt;/BODY&gt;</FONT></P>
<P><FONT size=3D2>&lt;/HTML&gt;</FONT></P>
<P><FONT=20
size=3D2>-------------------------------------------------------------</F=
ONT></P>
<P><FONT color=3D#000000 size=3D2>checkpassword.asp</FONT></P><FONT =
color=3D#800000>
<P><FONT size=3D2>&lt;%</FONT></P>
<P><FONT size=3D2>CONST useSession =3D TRUE</FONT></P>
<P><FONT size=3D2>' Retrieve Form Variables</FONT></P>
<P><FONT size=3D2>username =3D TRIM( Request( "username" ) )</FONT></P>
<P><FONT size=3D2>password =3D TRIM( Request( "password" ) )</FONT></P>
<P><FONT size=3D2>newUser =3D TRIM( Request( "newUser" ) )</FONT></P>
<P><FONT size=3D2>newUsername =3D TRIM( Request( "newUsername" ) =
)</FONT></P>
<P><FONT size=3D2>newPassword =3D TRIM( Request( "newPassword" ) =
)</FONT></P>
<P><FONT size=3D2>addCookie =3D TRIM( Request( "addCookie" ) =
)</FONT></P>
<P><FONT size=3D2>' Retrieve Current Page</FONT></P>
<P><FONT size=3D2>nextPage =3D Request.ServerVariables( "SCRIPT_NAME" =
)</FONT></P>
<P><FONT size=3D2>' Ready Database Connection</FONT></P>
<P><FONT size=3D2>Set Con =3D Server.CreateObject( "ADODB.Connection" =
)</FONT></P>
<P><FONT size=3D2>Con.Open "userDNS"</FONT></P>
<P><FONT size=3D2>' Add New User</FONT></P>
<P><FONT size=3D2>IF newUser &lt;&gt; "" THEN</FONT></P>
<P><FONT size=3D2>IF newUsername =3D "" THEN</FONT></P>
<P><FONT size=3D2>showError "You must enter a username"</FONT></P>
<P><FONT size=3D2>END IF</FONT></P>
<P><FONT size=3D2>IF newPassword =3D "" THEN</FONT></P>
<P><FONT size=3D2>showError "You must enter a password"</FONT></P>
<P><FONT size=3D2>END IF</FONT></P>
<P><FONT size=3D2>IF usernameTaken( newUsername ) THEN</FONT></P>
<P><FONT size=3D2>showError "The username you entered has already "=20
&amp;_</FONT></P>
<P><FONT size=3D2>"been chosen by a previous user. Please select "=20
&amp;_</FONT></P>
<P><FONT size=3D2>"a new username"</FONT></P>
<P><FONT size=3D2>END IF</FONT></P>
<P><FONT size=3D2>sqlString =3D "INSERT INTO userlist ( user_username, =
user_password=20
) " &amp;_</FONT></P>
<P><FONT size=3D2>"VALUES ('" &amp; newUsername &amp; "','" &amp; =
newPassword=20
&amp; "')"</FONT></P>
<P><FONT size=3D2>Con.Execute sqlString</FONT></P>
<P><FONT size=3D2>username =3D newUsername</FONT></P>
<P><FONT size=3D2>password =3D newPassword</FONT></P>
<P><FONT size=3D2>IF useSession THEN Session( "loggedIn" ) =3D =
"Yes"</FONT></P>
<P><FONT size=3D2>END IF</FONT></P>
<P><FONT size=3D2>' Authenticate User</FONT></P>
<P><FONT size=3D2>IF Session( "loggedIn" ) =3D "" THEN </FONT></P>
<P><FONT size=3D2>IF username =3D "" OR password =3D "" THEN</FONT></P>
<P><FONT size=3D2>loginMessage =3D "You must login before you can view =
this=20
page."</FONT></P>
<P><FONT size=3D2>showLogin</FONT></P>
<P><FONT size=3D2>END IF</FONT></P>
<P><FONT size=3D2>result =3D validateLogin( username, password =
)</FONT></P>
<P><FONT size=3D2>IF result =3D 1 THEN</FONT></P>
<P><FONT size=3D2>loginMessage =3D "You entered an unregistered=20
username."</FONT></P>
<P><FONT size=3D2>showLogin</FONT></P>
<P><FONT size=3D2>END IF</FONT></P>
<P><FONT size=3D2>IF result =3D 2 THEN</FONT></P>
<P><FONT size=3D2>loginMessage =3D "You did not enter a valid =
password."</FONT></P>
<P><FONT size=3D2>showLogin</FONT></P>
<P><FONT size=3D2>END IF</FONT></P>
<P><FONT size=3D2>IF useSession THEN Session( "loggedIn" ) =3D =
"Yes"</FONT></P>
<P><FONT size=3D2>END IF</FONT></P>
<P><FONT size=3D2>' Add a Cookie</FONT></P>
<P><FONT size=3D2>IF addCookie &lt;&gt; "" THEN</FONT></P>
<P><FONT size=3D2>Response.Cookies( "username" ) =3D username</FONT></P>
<P><FONT size=3D2>Response.Cookies( "username" ).Expires =3D =
"12/25/2037"</FONT></P>
<P><FONT size=3D2>Response.Cookies( "password" ) =3D password</FONT></P>
<P><FONT size=3D2>Response.Cookies( "password" ).Expires =3D =
"12/25/2037"</FONT></P>
<P><FONT size=3D2>END IF</FONT></P>
<P><FONT size=3D2>' Create Security Query String Variable</FONT></P>
<P><FONT size=3D2>sq =3D "username=3D" &amp; Server.HTMLEncode( username =
) &amp;=20
"&amp;"</FONT></P>
<P><FONT size=3D2>sq =3D sq &amp; "password=3D" &amp; Server.HTMLEncode( =
password )=20
</FONT></P>
<P><FONT size=3D2>' Create Security Form Variable</FONT></P>
<P><FONT size=3D2>sf =3D "&lt;input name=3D""username"" =
type=3D""hidden"" "</FONT></P>
<P><FONT size=3D2>sf =3D sf &amp; "value=3D""" &amp; Server.HTMLEncode( =
username )=20
&amp; """&gt;"</FONT></P>
<P><FONT size=3D2>sf =3D sf &amp; "&lt;input name=3D""password"" =
type=3D""hidden""=20
"</FONT></P>
<P><FONT size=3D2>sf =3D sf &amp; "value=3D""" &amp; Server.HTMLEncode( =
password )=20
&amp; """&gt;"</FONT></P>
<P><FONT size=3D2>' Check Username and Password</FONT></P>
<P><FONT size=3D2>FUNCTION validateLogin( theUsername, thePassword =
)</FONT></P>
<P><FONT size=3D2>sqlString =3D "SELECT user_password FROM userlist "=20
&amp;_</FONT></P>
<P><FONT size=3D2>"WHERE user_username=3D'" &amp; fixQuotes( username ) =
&amp; "'"=20
</FONT></P>
<P><FONT size=3D2>Set RS =3D Con.Execute( sqlString )</FONT></P>
<P><FONT size=3D2>IF RS.EOF THEN</FONT></P>
<P><FONT size=3D2>validateLogin =3D 1</FONT></P>
<P><FONT size=3D2>ELSE</FONT></P>
<P><FONT size=3D2>IF RS( "user_password" ) &lt;&gt; thePassword =
THEN</FONT></P>
<P><FONT size=3D2>validateLogin =3D 2</FONT></P>
<P><FONT size=3D2>ELSE</FONT></P>
<P><FONT size=3D2>validateLogin =3D 0</FONT></P>
<P><FONT size=3D2>END IF</FONT></P>
<P><FONT size=3D2>END IF</FONT></P>
<P><FONT size=3D2>END FUNCTION</FONT></P>
<P><FONT size=3D2></FONT>&nbsp;</P>
<P><FONT size=3D2>' Check Whether Username Already Taken</FONT></P>
<P><FONT size=3D2>FUNCTION usernameTaken( theUsername )</FONT></P>
<P><FONT size=3D2>sqlString =3D "SELECT user_id FROM userlist " =
&amp;_</FONT></P>
<P><FONT size=3D2>"WHERE user_username=3D'" &amp; fixQuotes( theUsername =
) &amp;=20
"'"</FONT></P>
<P><FONT size=3D2>Set RS =3D Con.Execute( sqlString )</FONT></P>
<P><FONT size=3D2>IF RS.EOF THEN</FONT></P>
<P><FONT size=3D2>usernameTaken =3D FALSE</FONT></P>
<P><FONT size=3D2>ELSE</FONT></P>
<P><FONT size=3D2>usernameTaken =3D TRUE</FONT></P>
<P><FONT size=3D2>END IF</FONT></P>
<P><FONT size=3D2>RS.Close</FONT></P>
<P><FONT size=3D2>Set RS =3D Nothing</FONT></P>
<P><FONT size=3D2>END FUNCTION</FONT></P>
<P><FONT size=3D2>' Show Error Page</FONT></P>
<P><FONT size=3D2>SUB showError( theError )</FONT></P>
<P><FONT size=3D2>%&gt;</FONT></P></FONT>
<P><FONT color=3D#0000c0><FONT size=3D2>&lt;HTML&gt;</FONT></P></FONT>
<P><FONT size=3D2><FONT =
color=3D#0000c0>&lt;HEAD&gt;&lt;TITLE&gt;</FONT>Problem<FONT=20
color=3D#0000c0>&lt;/TITLE&gt;&lt;/HEAD&gt;</P></FONT></FONT>
<P><FONT color=3D#0000c0><FONT size=3D2>&lt;BODY&gt;</FONT></P></FONT>
<P><FONT size=3D2><FONT color=3D#0000c0>&lt;b&gt;</FONT>There was a =
problem with=20
your registration information<FONT =
color=3D#0000c0>&lt;/b&gt;</P></FONT></FONT>
<P><FONT size=3D2><FONT color=3D#0000c0>&lt;br&gt;</FONT><FONT=20
color=3D#800000>&lt;%=3DtheError %&gt;</P></FONT></FONT>
<P><FONT size=3D2><FONT color=3D#0000c0>&lt;FORM =
METHOD=3D</FONT>"POST"<FONT=20
color=3D#0000c0> ACTION=3D</FONT>"register.asp"<FONT=20
color=3D#0000c0>&gt;</P></FONT></FONT>
<P><FONT size=3D2><FONT color=3D#0000c0>&lt;INPUT =
NAME=3D</FONT>"nextpage"<FONT=20
color=3D#0000c0> TYPE=3D</FONT>"hidden"</FONT></P><FONT color=3D#0000c0>
<P><FONT size=3D2>VALUE=3D</FONT></FONT><FONT size=3D2><FONT=20
color=3D#000000>"</FONT><FONT =
color=3D#800000>&lt;%=3Dnextpage%&gt;</FONT><FONT=20
color=3D#000000>"</FONT><FONT color=3D#0000c0>&gt;</P></FONT></FONT>
<P><FONT size=3D2><FONT color=3D#0000c0>&lt;INPUT =
NAME=3D</FONT>"newUsername"<FONT=20
color=3D#0000c0> TYPE=3D</FONT>"hidden"</FONT></P><FONT color=3D#0000c0>
<P><FONT size=3D2>VALUE=3D</FONT></FONT><FONT size=3D2><FONT=20
color=3D#000000>"</FONT><FONT color=3D#800000>&lt;%=3DServer.HTMLEncode( =
newUsername=20
)%&gt;</FONT><FONT color=3D#000000>"</FONT><FONT=20
color=3D#0000c0>&gt;</P></FONT></FONT>
<P><FONT size=3D2><FONT color=3D#0000c0>&lt;INPUT =
NAME=3D</FONT>"newPassword"<FONT=20
color=3D#0000c0> TYPE=3D</FONT>"hidden"</FONT></P><FONT color=3D#0000c0>
<P><FONT size=3D2>VALUE=3D</FONT></FONT><FONT size=3D2><FONT=20
color=3D#000000>"</FONT><FONT color=3D#800000>&lt;%=3DServer.HTMLEncode( =
newPassword=20
)%&gt;</FONT><FONT color=3D#000000>"</FONT><FONT=20
color=3D#0000c0>&gt;</P></FONT></FONT>
<P><FONT size=3D2><FONT color=3D#0000c0>&lt;INPUT =
TYPE=3D</FONT>"SUBMIT"<FONT=20
color=3D#0000c0> VALUE=3D</FONT>"Continue"<FONT =
color=3D#0000c0>&gt;</P></FONT></FONT>
<P><FONT color=3D#0000c0><FONT size=3D2>&lt;/FORM&gt;</FONT></P></FONT>
<P><FONT color=3D#0000c0><FONT size=3D2>&lt;/BODY&gt;</FONT></P></FONT>
<P><FONT color=3D#0000c0><FONT size=3D2>&lt;/HTML&gt;</FONT></P></FONT>
<P><FONT color=3D#800000><FONT size=3D2>&lt;%</FONT></P>
<P><FONT size=3D2>Response.End</FONT></P>
<P><FONT size=3D2>END SUB</FONT></P>
<P><FONT size=3D2>' Show the Login Page</FONT></P>
<P><FONT size=3D2>SUB showLogin</FONT></P>
<P><FONT size=3D2>%&gt;</FONT></P></FONT>
<P><FONT color=3D#808080><FONT size=3D2>&lt;!-- #INCLUDE =
FILE=3D"login.asp"=20
--&gt;</FONT></P></FONT>
<P><FONT color=3D#800000 size=3D1><FONT size=3D2>&lt;%</FONT></P>
<P><FONT size=3D2>Response.End</FONT></P>
<P><FONT size=3D2>END SUB</FONT></P>
<P><FONT size=3D2>FUNCTION fixQuotes( theString )</FONT></P>
<P><FONT size=3D2>fixQuotes =3D REPLACE( theString, "'", "''" =
)</FONT></P>
<P><FONT size=3D2>END FUNCTION</FONT></P>
<P><FONT =
size=3D2>%&gt;</FONT></P></FONT></FONT></DIV></FONT></DIV></BODY></HTML>

------=_NextPart_000_0026_01C45737.68254FB0--

Re: To hard to solve? by Stefan

Stefan
Mon Jun 21 04:38:19 CDT 2004

Take a look at http://support.microsoft.com/default.aspx?scid=321439

--

_____________________________________________
SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
"Warning - Using the F1 Key will not break anything!" (-;
To find the best Newsgroup for FrontPage support see:
http://www.net-sites.com/sitebuilder/newsgroups.asp
_____________________________________________


"Wayne Smith" <wayne.smith2004(NoSpam)@ntlworld.com> wrote in message news:%23nuZ67yVEHA.1952@TK2MSFTNGP12.phx.gbl...
Applies to: Microsoft FrontPage 2000, Microsoft Access 2000, IIS 5.0
Operating System: Microsoft Windows 2000 Professional

I am trying to protect a portion of a web site by allowing users to register a username and password & then login with those
details, but so far I am having only marginal success. I am far from an expert on ASP programming, indeed the code I am using comes
from "Sams Teach Yourself E-Commerce Programming with ASP" but it is ideally suited for my purpose.

In short, there are 3 .asp pages (register.asp, login.asp & checkpassword.asp - the code for each is below), a global.asa file was
automatically created and by following the instructions in the book, I also created a small Access database called UserDB.mdb, which
stores the username & password of each user when they register & also verify's those details when the user attempts to login again.

The DNS connection has been setup within FrontPage and I have verified that this connection works by clicking "Tools", "Web
Settings" & the "Database" tab, highlighting the DNS connection & clicking Verify.

The problems seem to occur when I try to register a new username & password, for some strange reason the details I enter are not
being saved in the database table, and to compound the problem further, if I register just a username, or a password but not both,
the page simply refreshes itself with empty boxes instead of giving an error message to indicate that a "username" or "password"
must be entered, which if I have read the code correctly on the "checkpassword.asp" page, should happen.

To further confuse the situation, if I manually enter a username & password into the database table and then attempt to click a
hyperlink taking me to a "test.asp" page, with the INCLUDE FILE: <!-- #INCLUDE FILE="checkpassword.asp" -->, I am automatically
taken to the login.asp, where if I enter the username & password that I manually put into the database table, it takes me to the
selected "Protected" web page. In my mind that clearly shows the DNS connection is working but yet it won't store new registered
details into the database table, which is extremely confusing.

If anyone can see what I may be doing wrong, or point me in the right direction, your help & advice will be greatly appreciated. As
I pointed out earlier I am far from an expert, so any help you can give would be ideally suited towards a newbie mentality.

Below is the code for the three .asp pages:

Many thanks in advance
Wayne Smith



register.asp

<%
nextPage = Request( "nextPage" )

newUsername = Request( "newUsername" )

newPassword = Request( "newPassword" )

%>

<HTML>

<HEAD><TITLE>Register"</TITLE></HEAD>

<BODY>

Register at this Web site by selecting a username and password:

<FORM METHOD="post" ACTION="<%=nextPage%>">

<INPUT NAME="newUser" TYPE="hidden" VALUE="1">

<P><B>USERNAME:</B>

<INPUT NAME="newUsername" SIZE=20 MAXLENGTH="20"

VALUE="<%=Server.HTMLEncode( newUsername )%>">

<P><B>PASSWORD:</B>

<INPUT NAME="newPassword" SIZE=20 MAXLENGTH="20"

VALUE="<%=Server.HTMLEncode( newPassword )%>">

<P><INPUT TYPE="submit" VALUE="Register!">

</FORM>

</BODY>

</HTML>

----------------------------------------------------------------------------------

login.asp

<HTML>

<HEAD><TITLE>Login</TITLE></HEAD>

<BODY>

<%=loginMessage%>

<FORM METHOD="post" ACTION="<%=nextPage%>">

<P><B>USERNAME:</B>

<INPUT NAME="username" SIZE=20 MAXLENGTH="20"

VALUE="<%=Server.HTMLEncode( username )%>">

<P><B>PASSWORD:</B>

<INPUT NAME="password" SIZE=20 MAXLENGTH="20"

VALUE="<%=Server.HTMLEncode( password )%>">

<p><INPUT NAME="addCookie" TYPE="Checkbox" VALUE="1"> Remember me with a cookie

<P><INPUT TYPE="submit" VALUE="Login">

</FORM>

<p>

<a href="register.asp?nextpage=<%Server.URLEncode( nextpage )%>">

Click here to register</a>

</BODY>

</HTML>

-------------------------------------------------------------

checkpassword.asp

<%

CONST useSession = TRUE

' Retrieve Form Variables

username = TRIM( Request( "username" ) )

password = TRIM( Request( "password" ) )

newUser = TRIM( Request( "newUser" ) )

newUsername = TRIM( Request( "newUsername" ) )

newPassword = TRIM( Request( "newPassword" ) )

addCookie = TRIM( Request( "addCookie" ) )

' Retrieve Current Page

nextPage = Request.ServerVariables( "SCRIPT_NAME" )

' Ready Database Connection

Set Con = Server.CreateObject( "ADODB.Connection" )

Con.Open "userDNS"

' Add New User

IF newUser <> "" THEN

IF newUsername = "" THEN

showError "You must enter a username"

END IF

IF newPassword = "" THEN

showError "You must enter a password"

END IF

IF usernameTaken( newUsername ) THEN

showError "The username you entered has already " &_

"been chosen by a previous user. Please select " &_

"a new username"

END IF

sqlString = "INSERT INTO userlist ( user_username, user_password ) " &_

"VALUES ('" & newUsername & "','" & newPassword & "')"

Con.Execute sqlString

username = newUsername

password = newPassword

IF useSession THEN Session( "loggedIn" ) = "Yes"

END IF

' Authenticate User

IF Session( "loggedIn" ) = "" THEN

IF username = "" OR password = "" THEN

loginMessage = "You must login before you can view this page."

showLogin

END IF

result = validateLogin( username, password )

IF result = 1 THEN

loginMessage = "You entered an unregistered username."

showLogin

END IF

IF result = 2 THEN

loginMessage = "You did not enter a valid password."

showLogin

END IF

IF useSession THEN Session( "loggedIn" ) = "Yes"

END IF

' Add a Cookie

IF addCookie <> "" THEN

Response.Cookies( "username" ) = username

Response.Cookies( "username" ).Expires = "12/25/2037"

Response.Cookies( "password" ) = password

Response.Cookies( "password" ).Expires = "12/25/2037"

END IF

' Create Security Query String Variable

sq = "username=" & Server.HTMLEncode( username ) & "&"

sq = sq & "password=" & Server.HTMLEncode( password )

' Create Security Form Variable

sf = "<input name=""username"" type=""hidden"" "

sf = sf & "value=""" & Server.HTMLEncode( username ) & """>"

sf = sf & "<input name=""password"" type=""hidden"" "

sf = sf & "value=""" & Server.HTMLEncode( password ) & """>"

' Check Username and Password

FUNCTION validateLogin( theUsername, thePassword )

sqlString = "SELECT user_password FROM userlist " &_

"WHERE user_username='" & fixQuotes( username ) & "'"

Set RS = Con.Execute( sqlString )

IF RS.EOF THEN

validateLogin = 1

ELSE

IF RS( "user_password" ) <> thePassword THEN

validateLogin = 2

ELSE

validateLogin = 0

END IF

END IF

END FUNCTION



' Check Whether Username Already Taken

FUNCTION usernameTaken( theUsername )

sqlString = "SELECT user_id FROM userlist " &_

"WHERE user_username='" & fixQuotes( theUsername ) & "'"

Set RS = Con.Execute( sqlString )

IF RS.EOF THEN

usernameTaken = FALSE

ELSE

usernameTaken = TRUE

END IF

RS.Close

Set RS = Nothing

END FUNCTION

' Show Error Page

SUB showError( theError )

%>

<HTML>

<HEAD><TITLE>Problem</TITLE></HEAD>

<BODY>

<b>There was a problem with your registration information</b>

<br><%=theError %>

<FORM METHOD="POST" ACTION="register.asp">

<INPUT NAME="nextpage" TYPE="hidden"

VALUE="<%=nextpage%>">

<INPUT NAME="newUsername" TYPE="hidden"

VALUE="<%=Server.HTMLEncode( newUsername )%>">

<INPUT NAME="newPassword" TYPE="hidden"

VALUE="<%=Server.HTMLEncode( newPassword )%>">

<INPUT TYPE="SUBMIT" VALUE="Continue">

</FORM>

</BODY>

</HTML>

<%

Response.End

END SUB

' Show the Login Page

SUB showLogin

%>

<!-- #INCLUDE FILE="login.asp" -->

<%

Response.End

END SUB

FUNCTION fixQuotes( theString )

fixQuotes = REPLACE( theString, "'", "''" )

END FUNCTION

%>