Make your own free website on Tripod.com
Assignment 7

<% @language = "VBSCRIPT" %>

<%if request.cookies("userName") <> "" and request.cookies("password") <> "" then

session("userName") = request.cookies("userName")

session("password") = request.cookies("password")

response.redirect("Assignment7-1.asp?returning=true")

end if%>

<html>

<head>

<script language="Javascript">

function checkInputs() {

if (document.all.userName.value == "" || document.all.password.value == "") {

window.alert("Please enter a username and password.");

loginForm.userName.focus() }

else

document.all.loginForm.submit();

}

</script>

</head>

<body onload="loginForm.userName.focus()">

<form id = "loginForm" action = "Assignment7-1.asp?returning=false" method = "post">

User Name:&nbsp;<input name = "userName" type = "textbox" style = "position: absolute; left: 100">

<br><br>

Password:&nbsp;<input name = "password" type = "password" style = "position: absolute; left: 100">

<br><br>

<input type = "button" value = "Login" onclick = "checkInputs()" style = "position: absolute; left: 100">

<br><br>New user? Click <a href = "Assignment7-4.asp">here</a>.

</form>

</body>

</html>

Assignment 7.1

<%@language = vbscript%>

<%option explicit%>

<%if not request("returning") then

session("userName") = request("userName")

session("password") = request("password")

end if%>

<%dim connection, strConn, query, loginData

set connection = server.createobject("ADODB.Connection")

strConn = "Provider=Microsoft.Jet.OLEDB.4.0; "

strConn = strConn & "Data Source = c:\today\Assignment7.mdb"

connection.open strConn

query = "select * from Users where userName = '" _

& session("userName") & "' and password = '" & session("password") & "'"

set loginData = server.CreateObject("ADODB.Recordset")

loginData.open query, connection

if not loginData.eof then

loginData.MoveFirst

if loginData("userName") <> "" then

response.cookies("userName") = session("userName")

response.cookies("userName").expires = Date() + 21

response.cookies("password") = session("password")

response.cookies("password").expires = Date() + 21

session("firstName") = loginData("firstName")

session("colorPreference") = loginData("colorPreference")

response.redirect("Assignment7-2.asp")

end if

else

response.redirect("Assignment7.asp")

end if

loginData.close

set loginData = nothing

connection.close

set connection = nothing%>

Assignment 7.2

html>

<head>

</head>

<body bgcolor = "<%=session("colorPreference")%>">

<h1>Welcome,&nbsp;<%=session("firstName")%>!</h1>

<b>Not&nbsp;<%=session("firstName")%>?&nbsp;&nbsp;Click <a href="Assignment7-3.asp">here</a>.</b>

</body>

</html>

Assignment 7.3

<% @language = vbscript %>

<% response.cookies("userName") = ""

response.cookies("userName").expires = date() + 21

response.cookies("password") = ""

response.cookies("password").expires = date() + 21

response.redirect("Assignment7.asp") %>

Assignement 7.4

<% @language = vbscript %>

<head>

<script language="Javascript">

function checkInputs() {

if (document.all.userName.value == "" || document.all.password.value == "" || document.all.firstName.value == "" || document.all.colorPreference.value == "") {

window.alert("Please enter a username, password, first name and color preference.");

signUpForm.userName.focus(); }

else

document.all.signUpForm.submit();

}

</script>

</head>

<body onload="signUpForm.userName.focus()">

<form id = "signUpForm" action = "Assignment7-5.asp" method = "post">

User Name:&nbsp;<input name = "userName" type = "textbox" style = "position: absolute; left: 100">

<br><br>

Password:&nbsp;<input name = "password" type = "password" style = "position: absolute; left: 100">

<br><br>

First Name:&nbsp;<input name = "firstName" type = "textbox" style = "position: absolute; left: 100">

<br><br>

Color:&nbsp;<input name = "colorPreference" type = "textbox" style = "position: absolute; left: 100">

<br><br>

<input type = "button" value = "Login" onclick = "checkInputs()" style = "position: absolute; left: 100">

<br><br>

</form>

</body>

Assignment 7.5

<% @language = vbscript %>

<% option explicit %>

<% dim connection, strConn, insert

set connection = server.createobject("ADODB.Connection")

strConn = "Provider=Microsoft.Jet.OLEDB.4.0; "

strConn = strConn & "Data Source = c:\rider\InternetAppDevelopment\2001spring\Assignment7.mdb"

connection.open strConn

insert = "INSERT INTO users VALUES ('" & cstr(request("userName")) & "','" & _

cstr(request("password")) & "','" & cstr(request("firstName")) & "','" & _

cstr(request("colorPreference")) & "')"

connection.execute(insert)

session("userName") = request("userName")

session("password") = request("password")

session("firstName") = request("firstName")

session("colorPreference") = request("colorPreference")

connection.close

set connection = nothing

response.redirect("Assignment7-2.asp")

%>