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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CF password protection...

Status
Not open for further replies.

wazir

Vendor
Jun 3, 2007
2
0
0
GB
okay all, im trying to make a password protected section on the site. I've used the following code from ww.sys-con.com
from their Auguest CF article, written by Kelly Brown under heading "simple Security"

-------
<!--- Turn On Session variables --->
<cfapplication name=&quot;AccessSecurity&quot;
sessionmanagement=&quot;Yes&quot;
setclientcookies=&quot;Yes&quot;
sessiontimeout=&quot;#CreateTimeSpan(0, 2, 0, 0)#&quot;>

<!-- If not logged in, run login procedure --->
<CFIF NOT IsDefined(&quot;Session.user_id&quot;)>
<CFSET message=&quot;&quot;>
<!--- If submitting login form, process it --->
<CFIF IsDefined(&quot;Form.login&quot;)>
<!--- Check login and password --->
<cfquery name=&quot;check&quot; datasource=&quot;users&quot;>
SELECT user_id
FROM users
WHERE email='#FORM.securitylogin#'
and password='#FORM.securitypassword#'
</cfquery>
<!--- If user found set session variable,
otherwise set error message --->
<CFIF check.RecordCount IS NOT 0>
<CFSET Session.user_id=check.user_id>
<CFELSE>
<CFSET message=&quot;Invalid Login.&quot;>
</CFIF>
</CFIF>
<!--- If logging in or invalid login
show login form --->
<CFIF NOT IsDefined(&quot;Form.login&quot;) or
message IS NOT &quot;&quot;>
<html><head><title>User Login</title></head>
<body bgcolor=&quot;white&quot;>
<P align=&quot;CENTER&quot;><B>Login</B></P>
<CFIF message IS NOT &quot;&quot;>
<CFOUTPUT><P align=&quot;CENTER&quot;><FONT color=&quot;red&quot;>
<B>#message#</B></font></P>
</CFOUTPUT><P>
</CFIF>
<!--- Extract the current file name from template
path and append the url parameters--->
<CFOUTPUT>
<FORM
action=&quot;#GetFileFromPath(CF_TEMPLATE_PATH)
#?#CGI.QUERY_STRING#&quot; method=&quot;POST&quot;>
</cfoutput>
<!--- Create all passed in form variables as
hidden form fields --->
<CFIF IsDefined(&quot;Form.FieldNames&quot;)>
<CFLOOP INDEX=&quot;ThisVar&quot; list=&quot;#Form.FieldNames#&quot;>
<CFIF ThisVar IS NOT &quot;securitylogin&quot; AND
ThisVar IS NOT &quot;securitypassword&quot;>
<CFOUTPUT>
<input type=hidden
name=&quot;#ThisVar#&quot;
value=&quot;#Evaluate(&quot;Form.#ThisVar#&quot;)#&quot;>
</cfoutput>
</cfif>
</cfloop>
</cfif>
<DIV align=&quot;center&quot;>
<TABLE border=&quot;0&quot; cellspacing=&quot;0&quot;>
<TR>
<TD align=right><B>Email</B></TD>
<TD><input name=&quot;securitylogin&quot; size=40></TD>
</TR>
<TR>
<TD align=right><B>Password</B></TD>
<TD><input type=&quot;password&quot;
name=&quot;securitypassword&quot;
size=15></TD>
</TR>
</TABLE>
<P>
<input type=submit value=&quot;Login&quot; name=&quot;login&quot;>
</FORM>
</div>
</body>
</html>
<!--- Stop the template here when logging in,
ignoring the rest of page --->
<CFABORT>
</CFIF>
<!--- If our login was okay we fall through to the
rest of the page --->
</CFIF>
-----

Now i know that according to this it needs a datasource &quot;users&quot; and a table called &quot;users&quot;

now im not sure, i've made a table using ACCESS 2000 and made teh datasource... everything connects cept i get the follwing error :

&quot;Error Diagnostic Information
ODBC Error Code = 07001 (Wrong number of parameters)


[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.

Hint: The cause of this error is usually that your query contains a reference to a field which does not exist. You should verify that the fields included in your query exist and that you have specified their names correctly.


The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (14:1) to (14:41).&quot;

oh and line 14:1 to 14:41 is this :

&quot; <cfquery name=&quot;check&quot; datasource=&quot;users&quot;> &quot;

so now i wanna know is this not doable with an ACCESS base table !?!? if not then what should i use instead, and how do i set it up ?

and from reading that can you tell what are the fieldname inside the table ?? i know two are &quot;securitylogin&quot; and &quot;securitypassword&quot; but i KNOW im missing something.

PLEASE write back, i would appriciate if ANYONE could solve this! :)


Thanks again,
BB
 
This error usually occurs when you have some sort of error in your SQL. From reading your post I gathered (excuse me if I'm wrong :)) that you have two fields in your table named &quot;securitylogin&quot; and &quot;securitypassword&quot; but in your SQL you're trying to access them as &quot;email&quot; and &quot;password&quot; when it should be:
Code:
SELECT * 
FROM user 
WHERE securitylogin=&quot;#Form.securitylogin#&quot;
AND securitypassword=&quot;#Form.securitypassword#&quot;
This is assuming that your form fields are named &quot;securitylogin&quot; and &quot;securitypassword&quot; also.

The error message states that the error occured in a cfquery starting at line 14, but it is the complete cfquery that causes the error so you should look at the query not just the line where it starts.

Hope this helps,

Brommrrrrr [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top