It's 6.30 on a Sunday night, my brain is fried and I need help to spot an
error, otherwise the Allaire Demon will haunt my sleep tonight ;)
I am trying to get a login system working reusing some code from another
site, I think it was originally from a tutorial somewhere, it works but
always throws out the first attempt to login - i.e. you put in a correct
username & password and it rejects them, enter again and no problem, you are
logged in.
There are three pages involved -
index.htm
Just a form which calls results.cfm with userid and password
results.cfm
<cflock timeout="2" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<CFSET Session.LoggedIn = FALSE>
</cflock>
<CFQUERY name="CheckUser" datasource="interlink">
SELECT loginid, password, name, company_id, email
FROM members
WHERE loginid = '#Form.UserID#'
</CFQUERY>
<CFIF CheckUser.RecordCount GREATER THAN 0>
<CFIF CheckUser.password IS Form.PassWord>
<cflock timeout="2" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<CFSET Session.LoggedIn = TRUE>
<CFSET Session.UserID = CheckUser.loginid>
<CFSET Session.Username = CheckUser.name>
<CFSET Session.member_id = CheckUser.company_id>
<CFSET Session.email = CheckUser.email>
</cflock>
<CFELSE>
<CFSET Reason = "the password you\'ve typed is invalid. Try again">
</CFIF>
<CFELSE>
<CFOUTPUT>
<CFSET Reason = 'I could not find a user named #Form.UserID# here.'>
</CFOUTPUT>
</CFIF>
<CFIF Session.LoggedIn>
<SCRIPT LANGUAGE="JavaScript">self.location ='members.cfm';</SCRIPT>
<CFELSE>
<CFOUTPUT>
<SCRIPT>alert("Sorry! Your login was unsuccessful because #Reason#");
self.location="index.htm"; </SCRIPT>
</CFOUTPUT>
</CFIF>
application.cfm
<CFAPPLICATION NAME="memberslogin" SESSIONMANAGEMENT="Yes"
SESSIONTIMEOUT="#CreateTimeSpan(0,0,15,0)#"
APPLICATIONTIMEOUT="#CreateTimeSpan(0,0,15,0)#">
<cflock timeout="2" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<CFPARAM name="session.LoggedIn" DEFAULT="FALSE">
</cflock>
<cfoutput>
<CFIF #session.LoggedIn# IS "FALSE">
<CFIF (CGI.SCRIPT_NAME IS NOT "index.htm" AND CGI.SCRIPT_NAME IS NOT
"results.cfm")>
<SCRIPT LANGUAGE="JavaScript">alert("The system has detected an invalid
login.
You will be prompted for your login/password again.");
self.location ='index.htm';
</SCRIPT>
</CFIF>
</CFIF>
</cfoutput>
I just know this is going to be a "Doh!" moment, but thanks in advance to
anyone who can slap me on the head and point out to me where I am making a
fool of myself.
Wayne Putterill
[EMAIL PROTECTED]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists