Forums

This topic is locked

Need to check passcode in javascript before ...

Posted 25 Aug 2004 17:59:57
1
has voted
25 Aug 2004 17:59:57 Richard Georgiou posted:
Hi DMX Zone...

I'm using DWMX2004 and access 2000. I've got a testing server running Win2k3server (IIS6) the same as my host...

I've created a form that asks the user for a passcode and business. If the passcode starts with an x then the user gets to see the special prices page. If they enter a passcode that doesn't begin with an x then they get declined...

The passcode will be an x followed by the users postcode (xtn224qh). I want to record the string in an access database...

This page doesn't have to be totally secure just enough to stop the casual passerby...

So far I've created a page called guest.asp, setup the graphics, setup a form called form1. In the form there are questions: Passcode (textfield), Business (listbox). I've then created a insert record behavour and all works a treat...

All I need to do now is to make sure only people who's passcode starts with x get to the prices page. I was thinking about some kind of javascript? I know you could look at the source of the page and see the password but that's fine...

I'm not sure if I'm doing the right thing here by including my source if it's not allowed then I'm sorry...?!?

Source code thus far is:

<%@LANGUAGE="JAVASCRIPT"%>
<!--#include file="Connections/aquadsn.asp" -->
<%
// *** Edit Operations: declare variables

// set the form action variable
var MM_editAction = Request.ServerVariables("SCRIPT_NAME";
if (Request.QueryString) {
MM_editAction += "?" + Server.HTMLEncode(Request.QueryString);
}

// boolean to abort record edit
var MM_abortEdit = false;

// query string to execute
var MM_editQuery = "";
%>
<%
// *** Insert Record: set variables

if (String(Request("MM_insert") == "form1" {

var MM_editConnection = MM_aquadsn_STRING;
var MM_editTable = "Table1";
var MM_editRedirectUrl = "images/home.html";
var MM_fieldsStr = "f_passcode|value|f_business|value";
var MM_columnsStr = "passcode|',none,''|business|',none,''";

// create the MM_fields and MM_columns arrays
var MM_fields = MM_fieldsStr.split("|";
var MM_columns = MM_columnsStr.split("|";

// set the form values
for (var i=0; i+1 < MM_fields.length; i+=2) {
MM_fields[i+1] = String(Request.Form(MM_fields[i]));
}

// append the query string to the redirect URL
if (MM_editRedirectUrl && Request.QueryString && Request.QueryString.Count > 0) {
MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1)?"?":"&" + Request.QueryString;
}
}
%>
<%
// *** Insert Record: construct a sql insert statement and execute it

if (String(Request("MM_insert") != "undefined" {

// create the sql insert statement
var MM_tableValues = "", MM_dbValues = "";
for (var i=0; i+1 < MM_fields.length; i+=2) {
var formVal = MM_fields[i+1];
var MM_typesArray = MM_columns[i+1].split(",";
var delim = (MM_typesArray[0] != "none" ? MM_typesArray[0] : "";
var altVal = (MM_typesArray[1] != "none" ? MM_typesArray[1] : "";
var emptyVal = (MM_typesArray[2] != "none" ? MM_typesArray[2] : "";
if (formVal == "" || formVal == "undefined" {
formVal = emptyVal;
} else {
if (altVal != "" {
formVal = altVal;
} else if (delim == "'" { // escape quotes
formVal = "'" + formVal.replace(/'/g,"''" + "'";
} else {
formVal = delim + formVal + delim;
}
}
MM_tableValues += ((i != 0) ? "," : "" + MM_columns[i];
MM_dbValues += ((i != 0) ? "," : "" + formVal;
}
MM_editQuery = "insert into " + MM_editTable + " (" + MM_tableValues + " values (" + MM_dbValues + "";

if (!MM_abortEdit) {
// execute the insert
var MM_editCmd = Server.CreateObject('ADODB.Command');
MM_editCmd.ActiveConnection = MM_editConnection;
MM_editCmd.CommandText = MM_editQuery;
MM_editCmd.Execute();
MM_editCmd.ActiveConnection.Close();

if (MM_editRedirectUrl) {
Response.Redirect(MM_editRedirectUrl);
}
}

}
%>
<%
var aquadsn = Server.CreateObject("ADODB.Recordset";
aquadsn.ActiveConnection = MM_aquadsn_STRING;
aquadsn.Source = "SELECT * FROM Table1";
aquadsn.CursorType = 0;
aquadsn.CursorLocation = 2;
aquadsn.LockType = 1;
aquadsn.Open();
var aquadsn_numRows = 0;
%>
<HTML>
<HEAD>
<TITLE>fluorescence1600</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #000000;
margin-left: 15px;
margin-top: 15px;
}
.btext {
font-family: Verdana;
font-size: 11px;
}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--



function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#"!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape"&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?")>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function flvFSTI4(){//v1.01
this.style.filter="";}

function flvFSTI3(v1,v2){//v1.01
var v3;if (v1.filters[0]&&v1.filters[0].status==2){v1.filters[0].Stop();}if (v2==0){v3="blendTrans(Duration="+v1.STI8+"";}else {v3="revealTrans(Duration="+v1.STI8+",Transition="+(v2-1)+"";}v1.style.filter=v3;}

function flvFSTI2(){//v1.01
var v1,v2=document,v3=v2.STI4,v4;for (v4=0;v3&&v4<v3.length&&(v1=v3[v4])&&v1.STI5;v4++){if (v1.filters&&!v2.STI7){flvFSTI3(v1,v1.STI3);v1.filters[0].Apply();}v1.src=v1.STI5;if (v1.filters&&!v2.STI7){v1.filters[0].Play();}}}

function flvFSTI1(){//v1.01
// Copyright 2003, Marja Ribbers-de Vroed, FlevOOware (www.STI1.nl/dreamweaver/)
var v1=arguments,v2=document,v3;v2.STI4=new Array();v2.STI7=(navigator.userAgent.toLowerCase().indexOf("mac"!=-1);for (var v4=0;v4<v1.length-2;v4+=5){v3=MM_findObj(v1[v4]);if (v3){v3.STI5=v3.src;v3.STI6=v1[v4+1];v3.STI2=v1[v4+2];v3.STI3=v1[v4+3];v3.STI8=v1[v4+4];v2.STI4[v2.STI4.length]=v3;if (v3.filters&&!v2.STI7){flvFSTI3(v3,v3.STI2);v3.onfilterchange=flvFSTI4;v3.filters[0].Apply();}v3.src=v3.STI6;if (v3.filters&&!v2.STI7){v3.filters[0].Play();}}}}
//-->
</script>
<link href="images/aquacss.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY onLoad="MM_preloadImages('images/b_home_1.gif','images/b_about_1.gif','images/b_aquarium_1.gif','images/b_pond_1.gif','images/b_commercial_1.gif','images/b_contact_1.gif')">
<!-- ImageReady Slices (fluorescence1600.jpg) -->
<TABLE WIDTH=700 BORDER=0 CELLPADDING=0 CELLSPACING=2>
<TR>
<TD colspan="2" align="center" valign="middle"><img src="images/logo.gif" width="180" height="85"> </TD>
<TD>
<IMG SRC="images/images/guest_03.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD>
<IMG SRC="images/images/guest_04.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD>
<IMG SRC="images/images/guest_05.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD><a href="images/about.html" onMouseOver="flvFSTI1('Image2','images/b_about_1.gif',0,0,0.2,1)" onMouseOut="flvFSTI2()"><img src="images/b_about_0.gif" name="Image2" width="100" height="100" border="0" id="Image2"></a></TD>
<TD>
<IMG SRC="images/images/guest_07.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
</TR>
<TR>
<TD>
<IMG SRC="images/images/guest_08.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD>
<IMG SRC="images/images/guest_09.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD><IMG SRC="images/images/guestdark_10.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD><IMG SRC="images/images/guestdark_11.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD><IMG SRC="images/images/guestdark_12.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD>
<IMG SRC="images/images/guest_13.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD><a href="images/aquarium.html" onMouseOver="flvFSTI1('Image3','images/b_aquarium_1.gif',0,0,0.2,1)" onMouseOut="flvFSTI2()"><img src="images/b_aquarium_0.gif" name="Image3" width="100" height="100" border="0" id="Image3"></a></TD>
</TR>
<TR>
<TD>
<IMG SRC="images/images/guest_15.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD><img src="images/b_guest_1.gif" width="100" height="100"></TD>
<TD><IMG SRC="images/images/guestdark_17.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD><IMG SRC="images/images/guestdark_18.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD><IMG SRC="images/images/guestdark_19.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD>
<IMG SRC="images/images/guest_20.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD><a href="images/pond.html" onMouseOver="flvFSTI1('Image4','images/b_pond_1.gif',0,0,0.2,1)" onMouseOut="flvFSTI2()"><img src="images/b_pond_0.gif" name="Image4" width="100" height="100" border="0" id="Image4"></a></TD>
</TR>
<TR>
<TD><a href="images/home.html" onMouseOver="flvFSTI1('Image1','images/b_home_1.gif',0,0,0.2,1)" onMouseOut="flvFSTI2()"><img src="images/b_home_0.gif" name="Image1" width="100" height="100" border="0" id="Image1"></a></TD>
<TD>
<IMG SRC="images/images/guest_23.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD><IMG SRC="images/images/guestdark_24.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD><IMG SRC="images/images/guestdark_25.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD><IMG SRC="images/images/guestdark_26.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD>
<IMG SRC="images/images/guest_27.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD>
<IMG SRC="images/images/guest_28.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
</TR>
<TR>
<TD>
<IMG SRC="images/images/guest_29.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD><a href="images/contact.html" onMouseOver="flvFSTI1('Image6','images/b_contact_1.gif',0,0,0.2,1)" onMouseOut="flvFSTI2()"><img src="images/b_contact_0.gif" name="Image6" width="100" height="100" border="0" id="Image6"></a></TD>
<TD>
<IMG SRC="images/images/guest_31.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD>
<IMG SRC="images/images/guest_32.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD>
<IMG SRC="images/images/guest_33.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
<TD><a href="images/commercial.html" onMouseOver="flvFSTI1('Image5','images/b_commercial_1.gif',0,0,0.2,1)" onMouseOut="flvFSTI2()"><img src="images/b_commercial_0.gif" name="Image5" width="100" height="100" border="0" id="Image5"></a></TD>
<TD>
<IMG SRC="images/images/guest_35.gif" WIDTH=100 HEIGHT=100 ALT=""></TD>
</TR>
</TABLE>
<div id="Layer1" style="position:absolute; width:292px; height:192px; z-index:1; left: 226px; top: 125px;" class="text">
<p>To access our guest area you will need to enter your passcode and type of business. Please enter them as explained in your information pack.</p>
<form ACTION="<%=MM_editAction%>" METHOD="POST" name="form1">
<table width="237" border="0" align="center" cellspacing="2">
<tr class="text">
<td width="91">Passcode</td>
<td width="130"><input name="f_passcode" type="password" class="button" id="f_passcode"></td>
</tr>
<tr class="text">
<td>Business</td>
<td class="text"><select name="f_business" class="button" id="f_business">
<option value="Please Select">Please select</option>
<option value="Doctor">Doctor</option>
<option value="Dentist">Dentist</option>
<option value="Clinic">Clinic</option>
<option value="Other">Other</option>
</select></td>
</tr>
<tr class="text">
<td><div align="center">
</div></td>
<td><object classid="clsid27CDB6E-AE6D-11cf-96B8-444553540000" codebase="download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="20">
<param name="BGCOLOR" value="#001866">
<param name="movie" value="images/button1.swf">
<param name="quality" value="high">
<embed src="images/button1.swf" width="100" height="20" quality="high" pluginspage="www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" bgcolor="#001866" ></embed>
</object></td>
</tr>
</table>





<input type="hidden" name="MM_insert" value="form1">
</form>
<p>  </p>
</div>
<!-- End ImageReady Slices -->
</BODY>
</HTML>
<%
aquadsn.Close();
%>

Thanks
Richard Georgiou
Entity7

Replies

Replied 26 Aug 2004 10:46:30
26 Aug 2004 10:46:30 Richard Georgiou replied:
Me again with an update... I've created a submit button and linked it to the followinf code:

javascript:document.form1.submit();

Would it work if I put in (the javascript equilivent of) something like:

Submit the form if passcode begins with x, else reset?

Cheers
Richard Georgiou
entity7

Reply to this topic