Alpha DevCon 2018
Results 1 to 14 of 14

Thread: Tracking user logins for a web app

  1. #1
    VAR
    Real Name
    Mike Reed
    Join Date
    Apr 2000
    Location
    Phoenix, AZ
    Posts
    639

    Default Tracking user logins for a web app

    If you want to track some basic info on who is trying to log in to your web apps, you can use the tracking function that Alpha has already included in the Web Security system. Using this feature allows you to see what IP addresses are trying to login, if a given IP is always failing, then perhaps it is a hacker and you can block that IP. Or maybe a user is having trouble, then you see that pattern and of course, you can do other analysis of the data.

    In the Web Security Settings, under Login Options, check the "Login activity file" box. Then you have the option to save the login file to data folder, project data folder or a user defined function. The first 2 options work, but it saves the info in a text file in the respective data folder, meaning that you have to import the data into something else to do analysis. Consider using the 'User Defined Function'. Then the data is saved in a table, making the analysis much easier.

    Be sure to check the next 2 boxes, 'Login activity include failed' and 'Login activity include logout' so you have more complete trail of login's.

    Oh yeah, don't forget to publish the security files when you are done....

    I implemented this is in our system to do the tracking in a MySQL table.

    Here is the MySQL code to create the table:
    CREATE TABLE `login_log` (
    `ID` int(11) NOT NULL AUTO_INCREMENT,
    `USERID` varchar(20) DEFAULT NULL,
    `ACTION_TIME` datetime DEFAULT NULL,
    `IP` varchar(20) DEFAULT NULL,
    `PASSEXP` datetime DEFAULT NULL,
    `LOGINEXP` datetime DEFAULT NULL,
    `LOGINERROR` varchar(50) DEFAULT NULL,
    `LOGOUT` tinyint(1) DEFAULT NULL,
    `ULINK` varchar(40) DEFAULT NULL,
    PRIMARY KEY (`ID`)
    ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;


    Here is the code to place in the user defined function on the web security settings:

    dim cn as sql::Connection
    dim args as sql::Arguments

    args.set("userid",e.userid)
    args.set("action_time",now())
    args.set("ulink",e.ulink)
    args.set("passexp",e.passexp)
    args.set("loginexp",e.loginexp)
    args.set("loginerror",e.loginerror)
    args.set("ip",e.ip)
    args.set("logout",e.logout)

    sqlinsert = <<%A%
    insert into login_log
    (
    userid,
    action_time,
    ulink,
    passexp,
    loginexp,
    loginerror,
    ip,
    logout

    )
    values
    (
    :userid,
    :action_time,
    :ulink,
    :passexp,
    :loginexp,
    :loginerror,
    :ip,
    :logout
    )
    %A%
    cn_open = cn.open("your connection string")
    cn_exec = cn.execute(sqlinsert, args)

    cn.FreeResult()
    cn.Close()

    Mike
    Mike Reed
    Phoenix, AZ

  2. #2
    Member
    Real Name
    javier
    Join Date
    Jul 2012
    Location
    Madrid
    Posts
    147

    Default Re: Tracking user logins for a web app

    Thank you. Very useful.
    Cheers,
    Javier

  3. #3
    Member
    Real Name
    Omar Garcia
    Join Date
    Jun 2006
    Location
    Alamo, Texas
    Posts
    579

    Default Re: Tracking user logins for a web app

    Not sure what the deal is but the code won't fire.

  4. #4
    VAR
    Real Name
    Mike Reed
    Join Date
    Apr 2000
    Location
    Phoenix, AZ
    Posts
    639

    Default Re: Tracking user logins for a web app

    Hi,
    I'm sorry you are having trouble. Here are screen prints of the settings I have. I'm not sure what else to tell you.
    Attached Images Attached Images
    Last edited by Mike Reed; 08-28-2013 at 02:02 PM.
    Mike Reed
    Phoenix, AZ

  5. #5
    Member J.R. Noe's Avatar
    Real Name
    J.R. Noe
    Join Date
    Feb 2011
    Location
    Brandenburg, KY.
    Posts
    398

    Default Re: Tracking user logins for a web app

    Thank you Mike. Works great.

    Omar, I used the code exactly how Mike provided except the connection string. I used this:
    cn_open = cn.open("::Name::MyConString")
    So it may be that. Make sure your using the correct connection string.
    I once worked on an issue for days before I finally realized I was using a connection string for another app.

    -JR

  6. #6
    Member
    Real Name
    Tony Watts
    Join Date
    Mar 2010
    Posts
    390

    Default Re: Tracking user logins for a web app

    Mike
    I'm trying to duplicate your log tracking and I have done everything and have one question.
    For "Security Table Type" does it matter if it's DBF? Or does it need to be SQL.
    I know the log activity table I created is SQL
    But my users, groups, assignment, passwords are all still DBF tables.
    I have read concerning stories about converting these to SQL and would prefer not to do that unless I have to
    Thanks
    Tony

  7. #7
    VAR
    Real Name
    Mike Reed
    Join Date
    Apr 2000
    Location
    Phoenix, AZ
    Posts
    639

    Default Re: Tracking user logins for a web app

    The script is written to save the log tracking to a sql table. I don't believe it makes any difference if the actual tables for the security system are dbf or sql.

    Just an FYI, switching from dbf to sql tables for the security works fine. The tools Alpha provided helped and works quite well. I didn't really have any issues. Just took a little time and patience.

    Mike
    Mike Reed
    Phoenix, AZ

  8. #8
    Member
    Real Name
    Tim
    Join Date
    Nov 2012
    Posts
    86

    Default Re: Tracking user logins for a web app

    I realize that this is an older thread but am hopeful that someone will be able to address my problem.
    I've added the code attached and created the table. All seem to be correct but nothing happens.
    This is exactly what I need to do but cannot get it right. I've no doubt its something I'm doing wrong but clueless as to what.

    One difference is MariaDB with HeidiSQL as the front end. I can't think how this would matter but my knowledge of databases is weak. The table created perfectly and appears to work as it should. My problem might be my connection string, also attached, but I've tried it with every combination I know, which again is weak.

    Also, I'm not using the built-in login on the page. I have a login component. Not sure if or how that matters.

    Thank you for any help!


    Code.jpg
    Attached Files Attached Files

  9. #9
    VAR
    Real Name
    Mike Reed
    Join Date
    Apr 2000
    Location
    Phoenix, AZ
    Posts
    639

    Default Re: Tracking user logins for a web app

    The problem I think is with your cn_open = cn.open() command.

    The format needs to be like this: cn.open(“::Name::SalesToolsDB”)
    Mike Reed
    Phoenix, AZ

  10. #10
    Member
    Real Name
    Tim
    Join Date
    Nov 2012
    Posts
    86

    Default Re: Tracking user logins for a web app

    First of all, I can't tell you how much I appreciate you responding.
    I also thought that was where the problem was and do think it was incorrect but unfortunately that didn't fix it so I must have a problem elsewhere.

    Does it matter that I use a login page component verses the Alpha login option on Tabbedui pages? I wasn't sure if this made a difference or not.

  11. #11
    VAR
    Real Name
    Mike Reed
    Join Date
    Apr 2000
    Location
    Phoenix, AZ
    Posts
    639

    Default Re: Tracking user logins for a web app

    Well, then...

    A couple more things to check then.

    First put a debug statement in the function and run it to make no errors are occurring, especially check the the cn_open and cn_exec commands are returning True.
    If the cn_open is false, then something else is wrong with your connection to the server. If that doesn't open then obviously nothing else will work.

    If the cn_open returns true, but cn_exec is false, then a couple more things to check are:
    Is the data you are trying to insert in the table match the field element type? In other words are you trying to put characters into a decimal field or into a timedate field?
    Is the data a null value but the does the field in your table require a value?

    Mike
    Mike Reed
    Phoenix, AZ

  12. #12
    Member
    Real Name
    Tim
    Join Date
    Nov 2012
    Posts
    86

    Default Re: Tracking user logins for a web app

    I'm assuming debug(1) needs to be put in the User Function section under login options. But nothing shows up.

    As for the table field elements not matching, I used the ones in your example and haven't changed those at all.

  13. #13
    Member
    Real Name
    Tim
    Join Date
    Nov 2012
    Posts
    86

    Default Re: Tracking user logins for a web app

    OK. My apologies. Come to find out its been working and I could not tell. I have no clue why but it only adds external emails addresses. In other words, company users (myself included) will not show up.



    (later that day). I now know why it would not show some users. User id length. lol

    Thank you again for help with this.
    Last edited by Cygnux; 08-15-2017 at 05:08 PM.

  14. #14
    VAR
    Real Name
    Mike Reed
    Join Date
    Apr 2000
    Location
    Phoenix, AZ
    Posts
    639

    Default Re: Tracking user logins for a web app

    Glad it is working for you. Have a great day!
    Mike Reed
    Phoenix, AZ

Similar Threads

  1. Multiple logins by same user
    By Jeff Fried in forum Alpha Five Version 10 - Desktop Applications
    Replies: 6
    Last Post: 04-20-2013, 12:52 PM
  2. Capture user info after login and store in session variable - web app
    By tomcat in forum Application Server Version 11 - Web/Browser Applications
    Replies: 9
    Last Post: 08-25-2012, 05:28 PM
  3. function for user logins (for LDAP password integration)
    By sdkrahn in forum Application Server Version 10 - Web/Browser Applications
    Replies: 11
    Last Post: 05-08-2012, 02:42 PM
  4. web app with multiple user-tables
    By Steve Wood in forum Database Design
    Replies: 6
    Last Post: 08-09-2009, 10:43 PM
  5. Concurrent Logins of same User ID's?
    By csda1 in forum Application Server Version 8
    Replies: 15
    Last Post: 08-11-2007, 10:41 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •