<cfset uname= #Form.UserName#>
<cfset pass= #Form.Password#>
<!--- Get user's details from the database --->
<cfquery name="GetUser" datasource="login">
SELECT firstname, realname, title, password, username, passid, school, lastip, totallogins, lastbrowser, lastlogin, department
FROM Users
WHERE UserName = '#uname#'
AND Password = '#Pass#'
</cfquery>
<!--- Check if we have a winner! --->
<cfif GetUser.RecordCount gt 0>
<cfset enckey="pe11ter">
<!--- Store the user id in session variables and cookies. --->
<cfset Session.userID = GetUser.passid>
<cfset Session.firstname = GetUser.firstname>
<cfset Session.realname = GetUser.realname>
<cfset Session.schoolid = GetUser.school>
<cfset Session.password = GetUser.password>
<cfset Session.title = GetUser.title>
<cfset Session.department = GetUser.department>
<!--- If user exists, update his or her profile information --->
<!--- First get the old info - you may wish to use this somehow. Some of the login stats are --->
<!--- cumulative, so we add to the prior number, like TotalLogins--->
<cfset oldIP = getUser.LastIP>
<cfset oldBrowser = getUser.LastBrowser>
<cfset oldLogin = getUser.LastLogin>
<cfset TotLogins = getUser.TotalLogins>
<!--- Store the new info in variables --->
<cfset newIP = CGI.REMOTE_ADDR>
<cfset newBrowser = CGI.HTTP_USER_AGENT>
<cfset TotLogins = TotLogins + 1>
<cfquery Datasource="login" name="UpdateUser">
UPDATE Users
SET TotalLogins = #TotLogins#,
LastIP = '#newIP#',
LastBrowser = '#newBrowser#',
LastLogin = #CreateODBCDateTime(Now())#
WHERE passid = #session.UserID#
</cfquery>
<META HTTP-EQUIV=REFRESH CONTENT="0; URL=login2.cfm">
<cfelse>
<!--- User does not exist --->
<!--- Pass the variables back in the URL - message and UserName --->
<cfset loginpage = "index.cfm?Message=" & URLEncodedFormat("Invalid User Name/Password Combination")>
<cfset loginpage = loginpage & "&Name=" & URLEncodedFormat(#Form.UserName#)>
<cflocation url="#loginpage#">
</cfif>