Solved

Store login information in DB

Posted on 2007-03-26
6
184 Views
Last Modified: 2013-12-16
Hi, is there a way that i can capture the username,  time, date, and Client IP of someone logging on to a secure page on my site - with no end-user input? Currently, i am using:  
<cfset clientIP = cgi.REMOTE_ADDR>
<cfoutput>Client IP Address:  #CGI.REMOTE_ADDR#</cfoutput>
...using this code i can display the information to the user, but what i really want to do is capture every login in the database, automatically...So, the end-user logs in, sees what i have up there, and logs out.  without any input from the end- user, i would like to get an "idea" of who logged on, when, etc. and the information would be stored automatically. I have added a table in MS Access, relative to my other tables, to store the info.
Any ideas?
0
Comment
Question by:koozilla
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 18797303

Sure, after you validate the login, simply insert a record into the database with the username (or ID) as well as now() for the current date/time and cgi.remote_addr for the IP address.  

insert into logins ( loginDate, userName, IPaddress)
values (#now()#, '#username#', '#cgi.remote_addr#')
0
 

Author Comment

by:koozilla
ID: 18797710
Sounds great, but i have to admit that i am a little "too green"... how exactly should i add that information?
currently, i have an "index.cfm" page that is the login, then it goes to the "presentation.cfm" page.
I am guessing that the code you gave me would go on the "presentation.cfm" page... probably above the HTML tag....
am i on the right track here?  i am getting a syntax error... but that might be b/c the #Now()# date is different than what the DB is looking for...

<cfquery name="qData" datasource="MyDatasource">
SELECT *
FROM tblDataX
WHERE UserName='#Session.MM_Username#'
</cfquery>
<cfquery datasource="MyDatasource">
INSERT INTO tblDataX (loginDate, userName, IPaddress)>
values (#now()#, '#username#', '#cgi.remote_addr#')
</cfquery>
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 18799921

 No problem, when a user is logging in, you likely have a query to validate their username and password against the form field.   If the user has entered the correct username and password, you then probably continue on to create the session variable.  At that same time (a successful login) I would place the insert statement.   You don't want to place the insert on a page where the user just visits because it will login his page visits not his login, so only place the insert when you process the login.

 The query you show is from tblDataX, is that the real name?  I ask because you are fetching from that table and then inserting into the same table in the next query.  Not sure why.    If tblDataX is the table that holds the user's login information, you DO NOT want to insert their activity into that table, you want to add it into another table.. something like this...


<cfquery name="qData" datasource="MyDatasource">
 SELECT *
 FROM   Users
 WHERE UserName='#form.MM_Username#'
</cfquery>
<cfif qData.recordCount eq 0>
   ... error, user does not exist
<cfelseif qData.passwrd neq form.passwrd>
   ... invalid login
<cfelse>
   ... success, now create the user's session ...
  <cfset session.mm_username = form.username>

   ... success, now record a successful login ...
  <cfquery datasource="MyDatasource">
    INSERT INTO UserLogins (loginDate, userName, IPaddress)>
    values (#now()#, '#username#', '#cgi.remote_addr#')
  </cfquery>
</cfif>




0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

Author Comment

by:koozilla
ID: 18801761
YOU ROCK!!! thank you!!
one more question...  the information is going into an Access DB.. the "Date" is showing up but not the "Time" (hh:mm:ss:).  Any ideas?
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 18801894

 I don't really know access that well, but perhaps this change to the coldfusion would work.

 Take out #now()# and replace with

 #createODBCdateTime(now())#
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 18805192
koozilla:,

The Now() function should return the date and time.

If not, then you may have to set the "Format" property of the Date field in the Access table to something like this:
    yyyy-mm-dd hh:nn:ss AM/PM
... to display the date and time.

Hope this helps

Jeff Coachman
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question