Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to password protect a page.. just point me in R Dir

Status
Not open for further replies.

ckroon

Technical User
Aug 11, 2005
2
US
Hey all,
Newbie here so bear with.

I have a password page all set up. I will giving out logins and passwords to clients so they can see different mock ups of websites I am designing for them. I am looking for a tutorial on how to set this up: a certain login/password takes them to a certain page.

Just point me in the right Direction please.
Thanks!
 

If you are using VBScript, you could use the Select Case construct. This assumes that you've already validated the password and got the username in strUser:

<%
Select Case strUser
Case "John"
Response.Redirect("Index23.asp")
Case "Fred"
Response.Redirect("Index99.asp")
End Select
%>

It's even easier if their homepage is named after them. So John's homepage is called JohnIndex.htm and Fred's is called FredIndex.htm

<%
Response.Redirect(strUser & "Index.htm")
%>

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Here's one way....

Login Page
Code:
<%@ Language=VBScript %>
<%Response.Buffer = True%>
<html>
<head>
<meta NAME="GENERATOR" Content="Microsoft FrontPage 5.0">
<title>Leader Login Page</title>
<script language="javascript">
function noRightClick() {
if (event.button==2) {
alert('Sorry, while viewing our website your Right Click action has been disabled.')
}
}
document.onmousedown=noRightClick
</script>
</head>
<body bgcolor="#ffffff">

<script LANGUAGE="vbscript" RUNAT='Server'>


Response.Write"<form METHOD='post' ACTION='validate.asp' id='form1' name='form1'>"

Response.Write"<Table CellPadding=2 Width=100%>"	

Response.Write"<tr>"
Response.Write"<td width='185' rowspan='2'><img src='images/yourimage.gif'></td>"
Response.Write"<td width='7' valign='top' rowspan='2'>&nbsp;<p>&nbsp;</td>"
Response.Write"<td width='530' valign='bottom' align='center'><h2><br>"
Response.Write"<br>"
Response.Write"    Please Log In </h2>"
Response.Write"</td>"
Response.Write"</tr>"
Response.Write"<tr>"
Response.Write"<td width='530' valign='top'><font color=0000FF>Enter the login name and password you"
Response.Write"    where supplied, and press LOGIN to continue.</font> <br>"
Response.Write"<p>"
Response.Write"</td>"
Response.Write"</tr>"

Response.Write"</Table>"	

Response.Write"<BR>"

Response.Write"<Table CellPadding=2 Width=100%>"
	
	Response.Write"<TR>"
		Response.Write"<TD Align='Right' Width=50%><FONT color=000000>Name</FONT>&nbsp;"
		Response.Write"</TD>"
		Response.Write"<TD Align='Left' Width=40%><input id='Name' name='Name' SIZE='15'>"
		Response.Write"</TD>"
	Response.Write"</TR>"
	
	Response.Write"<TR>"
		Response.Write"<TD Align='Right'><FONT color=000000>Password</FONT>&nbsp;"
		Response.Write"</TD>"
		Response.Write"<TD Align='Left'><input TYPE='password' id='Password' name='Password' SIZE='15'>&nbsp;&nbsp;<FONT color=crimson>(Will appear as ****)</FONT>"
		Response.Write"</TD>"
	Response.Write"</TR>"
		
	Response.Write"<TR>"
		Response.Write"<TD>"
		Response.Write"</TD>"
		Response.Write"<TD><P>&nbsp;</P>"
		Response.Write"</TD>"
		Response.Write"<TD>"
		Response.Write"</TD>"
	Response.Write"</TR>"
		
	Response.Write"<TR>"
		Response.Write"<TD>"
		Response.Write"</TD>"
		Response.Write"<TD><input id='submit1' name='submit1' type='submit' value='LOGIN'>"
		Response.Write"</TD>"
		Response.Write"<TD>"
		Response.Write"</TD>"
	Response.Write"</TR>"
		
Response.Write"</Table>"	

Response.Write"<BR>"

Response.Write"<BR>"

Response.Write"</form>"

Response.Write"</FONT>"

</SCRIPT>
</body>

</html>

Validation Page

Code:
<%Response.Buffer = True%>
<html>
<head>
<%
Dim strRemoteIP
strRemoteIP =  LCase(Request.ServerVariables("REMOTE_ADDR"))    ' Client's IP address
%>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Login Page</title>
<script language="javascript">
function noRightClick() {
if (event.button==2) {
alert('Sorry, while viewing our website your Right Click action has been disabled.')
}
}
document.onmousedown=noRightClick
</script>
</head>

<body>
<SCRIPT LANGUAGE="vbscript" RUNAT="Server">


If Request.Form("Name") = "Someone" AND Request.Form("Password") = "TheirPassword" Then

Response.Write"<form name='SelectDen' action='next_page.asp' method='post'>"

Response.Write"<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='672' id='AutoNumber1'>"
  Response.Write"<tr>"
    Response.Write"<td width='195'>"
    Response.Write"<img border='0' src='images/yourimage.gif' width='195' height='193'></td>"
    Response.Write"<td width='477' >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font size='6'><br>"
Response.Write"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cub Scouts - PACK 62</font></td>"
  Response.Write"</tr>"
    Response.Write"<td width='672' colspan='2'><h3 align='center'>Select your Den Number &nbsp;"	


Dim MyArray
MyArray = array("","1","2","3","4","5","6","7")

With Response
 .write "<select name='Den-No'>" &vbcrlf
 ' Look for matching Den Type, load option form with that type.
		
 for each item in MyArray
   .write "<option value='" & item & "'"
  .write ">" & item & "</option>"
 Next
End With
		

Response.Write"</select>"
Response.Write"</h3>"
Response.Write"</td>"
  Response.Write"</tr>"
  Response.Write"<tr>"
    Response.Write"<td width='672' colspan='2'>"
    Response.Write"<p align='center'><input type='Submit' value='Submit'>"
Response.Write"</td>"
  Response.Write"</tr>"
Response.Write"</table>"
Response.Write"</form>"

Else

'Set a log file - give it a 1 hour life
If Request.Cookies("status") = "" Then
  Response.Cookies("status")= 1
  Response.Cookies("status").Expires=DateAdd("h",1,Now)
Else
  Response.Cookies("status")= Request.Cookies("status") + 1					
  Response.Cookies("status").Expires=DateAdd("h",1,Now)
End If

'Determine if we ban the IP address
If Request.Cookies("status") >= 4 Then 'Ban the address

    Set connupdate = Server.CreateObject( "ADODB.Connection" )
    Set rec = server.CreateObject("ADODB.Recordset")
    
    'Create connection to the table, and use OLEDB.4.0 driver
    connupdate.Open "Data Source=" & Server.Mappath("mydatabase.mdb") & ";Provider=Microsoft.Jet.OLEDB.4.0;"

    dim objRS
    set objRS = server.CreateObject("ADODB.Recordset")

   ' Set the cursor location to client side (3)
    objRS.CursorLocation = 3

    objRs.open "Select * from tblBannedIP where RecordID = 0", connupdate, 3, 3

    objRS.AddNew
              objRS.Fields("IP") = strRemoteIP
    objRS.Update
    objrs.Close

set objrs = Nothing
 connupdate.Close
set connupdate = nothing

    Response.Redirect "banned.asp"
Else
	Response.Write"<CENTER><FONT Color='Red' Size=6><B><U>INCORRECT LOGIN!</U><BR><BR>&nbsp;&nbsp;&nbsp; TRY AGAIN!</B></FONT>"
	Response.Write"<P>&nbsp;</P>"
	Response.Write"<FONT Color='Red' Size=6><A href='login.asp'>Click Here</A>&nbsp;to try again!</CENTER>"
End If
End If

</SCRIPT>

</body>

</html>

I'd reccommend the Select Case statement.
You can process this in one page, but i separated it for ease.

Just make sure the names and password are in response.write tags, or pull them from a database so that they can't be viewed in the source code.

has excellent examples of working with MS Access tables.

Good Luck

AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top