Skip to main content
Inspiring
May 22, 2008
Question

Urgent problem with login, Please help *Repost*

  • May 22, 2008
  • 2 replies
  • 629 views
Hello;

Sorry for reposting, this issue is driving me nuts, I even rewrote it using <cflogin> and it does the same thing!

I wrote a log in form for my application. I am locking out a directory that is in my web site root directory.

http://www.mysite.com/lockeddirectory/index.cfm

I have 2 application.cfc files, one in my root directory and one in the locked out directory. I have to use a proxyapplication.cfc to communicate between the file in the root and the locked directory. (I don't have server control)

Now the code i wrote for the log in works to a point. It does log me in, and it passes the variables to the pages I want it to. BUT when your logged into the locked directory, and you click on a link to go to one of the pages in that directory, it kicks you out and wants you to log in again. I can't figure out what I did wrong, can anyone help me out and help me tweek my code to make it work?

here is my code:

LoginCheck.cfm

<cfparam name="FORM.userLogin" type="string">
<cfparam name="FORM.userPassword" type="string">

<cfquery NAME="getUser" datasource="#APPLICATION.dataSource#">
SELECT user.id, user.Fname, user.Lname
FROM user
WHERE userName =<cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.UserLogin#">
AND password =<cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.UserPassword#">
</cfquery>

<cfif getUser.recordCount eq 1>
<cflock scope="Session" type="EXCLUSIVE" TIMEOUT="20">
<cfset SESSION.auth = structNew()>
<cfset SESSION.auth.isLoggedin = "yes">
<cfset SESSION.auth.id = getUser.id>
<cfset SESSION.auth.Fname = getUser.Fname>
</cflock>
<cfquery name="updateLoginInfo" datasource="#APPLICATION.dataSource#">
UPDATE user SET
lastLogin = #CreateOdbcDateTime(now())#,
hits = hits+1
WHERE ID = #val(getUser.Id)#
</cfquery>
<cflocation url="admin/index.cfm">
<cfelse>
<cflocation url="login.cfm?login=#form.UserLogin#&getUser=#getUser.recordCount#" addtoken="no">
</cfif>

Application.cfc file in locked directory:

<cfcomponent output="false" extends="ProxyApplication">
<cffunction name="OnRequestStart" output="false" returntype="void">
<cfif NOT isDefined("SESSION.auth.isLoggedIn")>
<cflocation url="../sitemanager.cfm" addtoken="no">
<cfabort>
<cfelseif isDefined("FORM.UserLogin")>
<cfinclude template="../LoginCheck.cfm">
</cfif>
</cffunction>
</cfcomponent>

I do have session management and cookies and everything turned on in the main application.cfc file. So I am confused on why this is looking to make me log back in everytime I click on a link in the protected directory.

Thank you

CFmonger
    This topic has been closed for replies.

    2 replies

    Known Participant
    May 23, 2008
    Yes, in your logincheck.cfm page. The code is just

    window.location="somewhere";

    So in your code example above try replacing the

    <cflocation url="admin/index.cfm">

    with

    <SCRIPT language="JavaScript">
    <!--
    window.location="admin/index.cfm";
    //-->
    </SCRIPT>
    CFmongerAuthor
    Inspiring
    May 23, 2008
    Now it won't let me log in at all. I tried just changing the one cflocation on teh LoginCheck.cfm, then both of them, and the one in the application.cfc in the locked directory. won't let me in now.

    here is the last code I tried:

    <cfparam name="FORM.userLogin" type="string">
    <cfparam name="FORM.userPassword" type="string">

    <cfquery NAME="getUser" datasource="#APPLICATION.dataSource#">
    SELECT user.id, user.Fname, user.Lname
    FROM user
    WHERE userName =<cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.UserLogin#">
    AND password =<cfqueryparam cfsqltype="cf_sql_varchar" value="#FORM.UserPassword#">
    </cfquery>

    <cfif getUser.recordCount eq 1>
    <cflock scope="Session" type="EXCLUSIVE" TIMEOUT="20">
    <cfset SESSION.auth = structNew()>
    <cfset SESSION.auth.isLoggedin = "yes">
    <cfset SESSION.auth.id = getUser.id>
    <cfset SESSION.auth.Fname = getUser.Fname>
    </cflock>
    <cfquery name="updateLoginInfo" datasource="#APPLICATION.dataSource#">
    UPDATE user SET
    lastLogin = #CreateOdbcDateTime(now())#,
    hits = hits+1
    WHERE ID = #val(getUser.Id)#
    </cfquery>
    <SCRIPT language="JavaScript">
    <!--
    window.location="admin/index.cfm";
    //-->
    </SCRIPT>
    <cfelse>
    <SCRIPT language="JavaScript">
    <!--
    window.location="sitemanager.cfm?login=#form.UserLogin#&getUser=#getUser.recordCount#";
    //-->
    </SCRIPT>
    </cfif>

    Applicaton.cfc

    <cfcomponent output="false" extends="ProxyApplication">

    <cffunction name="OnRequestStart" output="false" returntype="string">
    <cfif NOT isDefined("SESSION.auth.isLoggedIn")>
    <SCRIPT language="JavaScript">
    <!--
    window.location="../sitemanager.cfm";
    //-->
    </SCRIPT>
    <cfabort>
    <cfelseif isDefined("FORM.UserLogin")>
    <cfinclude template="../LoginCheck.cfm">
    <cfreturn true>
    </cfif>
    </cffunction>
    </cfcomponent>

    tried it in the cfc without changing to the script, and did the same thing, won't let me log in now.
    Known Participant
    May 23, 2008
    It used to be the case that if you tried to set a cookie on the same template as a cflocation then the cookie wouldn't get set. Maybe try replacing your cflocation with a javascript window.location and see if that makes a difference.
    CFmongerAuthor
    Inspiring
    May 23, 2008
    how is that written?
    and that would go on the LoginCheck.cfm page correct?