Copy link to clipboard
Copied
As funding is an issue, my hosting space is currently CF 6, and am stuck with this version for about another year, so I must make the best of it. I have a big challenge with CFLOGIN. My goal is to have family members sign into the family site, and have their navigation to go from page to page. I am baffled as to how to implement cookies, with a backup database to hold their login data, in case their machine is set to not allow cookies. I've got a lot of people waiting for me to accomplish this! The code here, is not CFLOGIN, but the book says it will!
Right now, the table in the database is named permissions, and the two fields are un and pw.
I am typing from the Inside Coldfusion MX book, by John Cummings. I looked at another book, by Ben Nadel, and typed his code verbatum also. I triple-checked every character, and things are not working with either code sets. The site is a family site, and security is not a big issue, but I wish to implement a login, anyway. I've no SSL (because its just a family site for now).
Here's the code from the book by John C. :
The title of this section of the book is "Conditional Logic for Authentication Processing" but things are not clear as to what goes into the application.cfm and what goes into the page.
in my application.cfm :
<cfapplication name = "dougs_mobile_site"
sessionTimeout = #CreateTimeSpan(0, 0, 0, 60)#
sessionManagement = "Yes">
<CFPARAM
NAME="family"
DEFAULT="9130.fam">
<CFERROR TYPE="Request" TEMPLATE="oops.cfm">
<cfif not IsDefined("LoggedIn")>
<cflocation url="login.cfm">
<cfelse>
<cfset LoggedIn="yes">
</cfif>
my login.cfm page :
<HTML>
<HEAD>
<TITLE>Login Page</TITLE>
</HEAD>
<BODY>
<CFINCLUDE TEMPLATE="login_form_.cfm">
</BODY>
</HTML>
in my cfinclude, named login_form_.cfm :
<!--- Remember the requested URL --->
<CFSET URL="http://" & cgi.server_name & ":" & cgi.server_port & cgi.script_name>
<CFIF cgi.query_string IS NOT " ">
<CFSET URL=url & "?#cgi.query_string#">
</CFIF>
<CFOUTPUT>
<FORM
ACTION="#url#"
METHOD="post">
<TABLE>
<TR>
<TD COLSPAN="2">
<HR>
</TD>
</TR>
<TR>
<TD ALIGN="center">
<TABLE>
<TR>
<TD ALIGN="center" COLSPAN="2">
You are not currently logged into the system.
</TD>
</TR>
<TR>
<TD ALIGN="right">
Username:
</TD>
<TD>
<INPUT TYPE="text" NAME="un">
</TD>
</TR>
<TR>
<TD ALIGN="right">
Password:
</TD>
<TD>
<INPUT TYPE="password" NAME="pw">
</TD>
</TR>
<TR>
<TD COLSPAN="2">
<INPUT TYPE="submit" NAME="send" VALUE="Login">
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</FORM>
</CFOUTPUT>
Copy link to clipboard
Copied
I realize I forgot the query. I put it into the application.cfm, but that didn't get it working, either:
The use of a query is obvious, but the book said nothing about it....
<CFSAVECONTENT VARIABLE="q_login">
<CFQUERY NAME="q_permissions" DATASOURCE="family">
SELECT permissions.* FROM permissions;
</CFQUERY>
</CFSAVECONTENT>
and, of course at the top of the login page:
<CFOUTPUT>
#q_login#
</CFOUTPUT>
Copy link to clipboard
Copied
Where does 'LoggedIn' get created? That's not obvious from your code.
<cfif not IsDefined("LoggedIn")>
What you should have is the page the form submits to should look up the username and password in the DB, then set the loggedin flag to true.
So probably at the top of login_form.cfm, something like:
<cfif structKeyExists(form, "un") and structKeyExists(Form, "pw")>
<CFQUERY NAME="q_permissions" DATASOURCE="family">
SELECT permissions.* FROM permissions
WHERE un = <cfqueryparam value="#form.un#" CFSQLType="CF_SQL_VARCHAR">
AND pw = <cfqueryparam value="#form.pw#" CFSQLType="CF_SQL_VARCHAR">
</CFQUERY>
<cfif q_permissions.recordCount EQ 1>
<!--- user can be logged in --->
<cfset LoggedIn = true>
<cflocation url="index.cfm">
</cfif>
</cfif>
(although ideally you'd be hashing your passwords not storing them as plaintext, right?)
This code is redundant:
<CFSET URL="http://" & cgi.server_name & ":" & cgi.server_port & cgi.script_name>
<CFIF cgi.query_string IS NOT " ">
<CFSET URL=url & "?#cgi.query_string#">
</CFIF>
<CFOUTPUT>
<FORM
ACTION="#url#"
METHOD="post">
Just use an empty action attribute, it'll do the same thing (of submitting to the current URL).
<FORM
ACTION=""
METHOD="post">