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!

Unexpected Login Errors-Especially 1st Time Logins

Status
Not open for further replies.

parly

Technical User
Aug 23, 2001
13
0
0
US
I'm using a login page that works fairly efficiently AFTER users have been 'helped' by me to get logged in properly for the first time. Here is application.cfm:

<cfapplication name=&quot;HR&quot; sessionmanagement=&quot;Yes&quot; sessiontimeout=&quot;#CreateTimeSpan(0,0,20,0)#&quot; applicationtimeout=&quot;#CreateTimeSpan(0,0,20,0)#&quot;>

<cferror type=&quot;REQUEST&quot; template=&quot;error.cfm&quot;>

<cfparam name=&quot;session.SSN&quot; default=&quot;False&quot;>
<cfparam name=&quot;session.LoggedIn&quot; default=&quot;false&quot;>
<cfparam name=&quot;session.LoginID&quot; default=&quot;false&quot;>

<cfset apptimespan = #createtimespan(0,0,20,0)#>

<CFIF #session.loggedin# IS &quot;False&quot;>

<CFIF (CGI.SCRIPT_NAME IS NOT &quot;login.cfm&quot;) AND (CGI.SCRIPT_NAME IS NOT &quot;results.cfm>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
alert(&quot;The system has detected an invalid login or your session on this machine has timed out. You will be prompted for your login/password again. If this error continues, try again in 20 minutes. We apologize for the inconvenience.&quot;);
self.location=&quot;login.cfm&quot;;
</SCRIPT>
</CFIF>

<CFELSE>

<CFIF (CGI.SCRIPT_NAME IS NOT &quot;login.cfm&quot;) AND (CGI.SCRIPT_NAME IS NOT &quot;results.cfm>
<CFSET APPLICATION.USERSLOGGEDIN[&quot;#Session.LoginID#&quot;].TIMECREATED = NOW()>
</CFIF>

</CFIF>

Users will often get &quot;timeout&quot; errors the first time they log in even if they use the right login name and password. I can 'fix' this error by changing the timeout from 20 to 0 minutes and then back again. I'm not understanding why this will happen. Is there something wrong with the code, or is there something I can add that will keep this from happening?

application.cfm feeds results.cfm. This page has session variables set for a pick list of all the applications that a user is set to see. All users are not allowed to see all applications, but another error that a first time logger will get is an unrecognized variable mentioning each one of the applications in turn.

The code on the actual menu page looks like this:

<cfif session.HRappName IS &quot;1&quot;>
<tr>
<td>
<a href=&quot;HRappName.cfm&quot;>HRappName</a>
</td>
</tr>
</cfif>

Each application name has a variable set and if I only comment out the first one, each if is &quot;1&quot; statement will get an error in its turn.

The code on results.cfm looks like this:


<cfset session.loggedin=false>

<cfquery name=&quot;CheckUser&quot; datasource=&quot;Master&quot;>

SELECT *
FROM Login
WHERE LoginID = '#Form.LoginID#'
</cfquery>

<cfset session.OneHRapp = &quot;#CheckUser.OneHRapp#&quot;>

<!---And a whole bunch more applications listed--->
<cfquery name=&quot;getSSN&quot; datasource=&quot;Master&quot;>
SELECT *
FROM Atable
WHERE SSN='#session.SSN#'
</cfquery>

<cfif CheckUser.RecordCount greater than 0>
<cfif CheckUser.PwsWd IS FORM.PwsWd>

<cfif #IsDefined(&quot;application.UsersLoggedIn&quot;)# IS False>
<cfset application.UsersLoggedIn=StructNew()>
</cfif>
<cfset UserIDatDoor=CheckUser.LoginID>


<cfif #StructKeyExists(application.UsersLoggedIn, UserIDatDoor)# IS True>

<cfset EndTime=#application.UsersLoggedIn[UserIDatDoor]. TimeCreated# + #AppTimeSpan#>

<cfif #DateCompare(&quot;#Now()#&quot;, &quot;#EndTime#&quot;)# IS 1>


<cfoutput>
<cfscript>
StructDelete(application.UsersLoggedin, #CheckUser.LoginID#, true);
</cfscript>
</cfoutput>

<cfset session.LoggedIn=True>
<cfset session.LoginID=CheckUser.LoginID>
<cfset application.UsersLoggedIn[&quot;#session.LoginID#&quot;]=Session>
<cfset applicaton.UsersLoggedIn[&quot;#Session.LoginID#&quot;]. TimeCreated=Now()>

<cfelse>

<cfoutput>
<cfif #DateDiff(&quot;n&quot;, &quot;#Now()#&quot;, &quot;#EndTime#&quot;)# LT 1>
<cfset MinutesLeft='Less Than One'>
<cfelse>
<CFSET MINUTESLEFT = #DATEDIFF(&quot;n&quot;, &quot;#Now()#&quot;, &quot;#EndTime#&quot;)#>
</cfif>

<cfset Reason = &quot;: \n\n1- User #CheckUser.LoginID# is already logged-in.\n2- OR you have terminated your last session abnormaly (e.g. your computer crashed).\n\nThis account will be unlocked in: #MinutesLeft# minute(s) from now.&quot;>
<!--- \n\nTo obtain more licenses, please contact our sales team. --->
</cfoutput>

</cfif>


<cfelse>


<cfset session.LoggedIn=True>
<cfset session.LoginID=CheckUser.LoginID>
<cfset application.UsersLoggedIn[&quot;#session.LoginID#&quot;] =Session>
<cfset application.UsersLoggedIn[&quot;#Session.LoginID#&quot;]. TimeCreated=Now()>

</cfif>

<cfelse>
<cfset Reason=&quot;The password you have typed is invalid. Please try again.&quot;>

</cfif>

<cfelse>

<cfoutput>

<cfset reason ='Program unable to find #FORM.LoginID#. Please try again or contact administrator.'>

</cfoutput>
</cfif>


<cfif session.LoggedIn>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
self.location =&quot;ActualMenuPage.cfm&quot;;
</SCRIPT>


<cfelse>

<cfoutput>
<SCRIPT>
alert(&quot;Sorry! Your login was unsuccessful because #Reason#&quot;);
self.location=&quot;login.cfm&quot;;
</SCRIPT>
</cfoutput>

</cfif>

<cfSET session.login_id = form.loginid>


<cfif (CheckUser.PwsWd) IS &quot;#CheckUser.SSN#&quot;>
<cflocation url=&quot;pswChng.cfm?SSN=#CheckUser.SSN#&quot; addtoken=&quot;Yes&quot;>
</cfif>

<cfif (CheckUser.PwsWd) IS NOT &quot;#CheckUser.SSN#&quot;>
<cflocation url=&quot;ActualMenuPage.cfm&quot; addtoken=&quot;Yes&quot;>
</cfif>



If a user calls me to say they are getting the unrecognized variable error I comment out the if statement, have them try again and they'll get in with no problem. Then I can make the code active and they won't have any more problems in future. The problem is exacerbated when someone from a different LAN attempts to login.

What am I not seeing here? Sorry this was so long and convoluted. I hope someone can shed some light on this.
 
Hi,

Have you tried printing out your application and session structures when someone has logged in to see if HRAppname is a session variable?

Create yourself a dummy account and put some debugging in your application.cfm to output your session structure and if the Session.HRAppname is not being set you may need to find out why. I think it may be because the timeout is wrong or because session management on your server isn't being set properly. Check your CF Administrator Settings for Session Management and ensure that the session variable timeout is set to 20 minutes.

Hope this all Helps

Duns
 
If I understand what you mean by making sure the session variable is set, i.e., &quot;HRappName&quot;, it is, I think. This error will not happen after the first time logging in. In other words, once the user logs in for the first time EVER, say, today, he can log in tomorrow or the next day and thereafter with no problems. Therefore the session variable is set. Can't I be assured that this is so because of the above result?
I'm fairly new to CF and don't know what you mean by putting some debugging into my application.cfm. Could you be a little more specific, or perhaps it's a mute point, in that I think the variable IS being set.
 
Are there any more suggestions?
 
You cannot use CFLOCATION on a page that sets cookies. SESSION variables use cookies.

A cookie is client side, whereas CFLOCATION is server side. A cookie is set when a page is fully loaded. If you use CFLOCATION it will redirect the page before the page fully loads. This is to your advantage if you don't want the entire page loaded. However, a cookie cannot be set using this. The alternative is to either use...

1. JavaScript:
a. location.href = &quot;mypage.cfm&quot;
b. location.replace(&quot;mypage.cfm&quot;) <-- I prefer this one

OR

2. Metatag
a. [COLOR=000080]<meta http-equiv=&quot;Refresh&quot; content=&quot;0 URL=&quot;mypage.cfm&quot;>[/color]

See:
1525

Try changing the script to this:

<cfif CheckUser.PwsWd IS CheckUser.SSN>
<CFOUTPUT>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
location.replace(&quot;pswChng.cfm?SSN=#CheckUser.SSN#&#CLIENT.URLToken#&quot;);
//-->
</SCRIPT>
</CFOUTPUT>
<cfelse>
<CFOUTPUT>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
location.replace(&quot;ActualMenuPage.cfm?#CLIENT.URLToken#&quot;);
//-->
</SCRIPT>
</CFOUTPUT>
</cfif> - tleish
 
hi parly

tleish is right, the meta tag should do what you need. You can also try CFHEADER. The page doesn't actually reload, the server delivers a different page.

CFHEADER will do what you need. But be sure to place it below the code you're having trouble with.

<CFSET actionURL = &quot;abc.cfm&quot;>
<!--- top --->
CODE
<!--- bottom --->
<CFHEADER name=&quot;refresh&quot; value=&quot;0; url=#actionURL#&quot;>

good luck

nic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top