lastlogin / lastaccess disparity

lastlogin / lastaccess disparity

by David Dixon -
Number of replies: 5

Hi folks

I wonder if anybody else has come across this. I have a 1.8.7 moodle install using ldap for authentication. I've noticed that there is a disparity between the lastlogin time recorded in the user table and the stats held in user_lastaccess. For example, quite a number accounts have zero in lastlogin yet data in the user_lastaccess table. First of all I thought this could be explained by people “logging is as”, but the issue is too widespread for this. Any ideas?

Foolishly I made some use of last login in some custom code I did, and it has come back to bite me.  I do understand, by the way, that last access and last login are not the same things.

Much appreciated

Dave

Average of ratings: -
In reply to David Dixon

Re: lastlogin / lastaccess disparity

by Aaron Wells -
This response may be a bit late, but I was just looking into the same thing and it may be helpful for other people. The crux of it is that 'lastlogin' actually records the last-but-one time that a user has logged in.

There are two related fields in the mdl_user table that get updated when a user logs in: 'currentlogin' and 'lastlogin'. Each time a user logs in:
- 'currentlogin' gets updated with the present time
- 'lastlogin' gets updated with the previous value of currentlogin.

So currentlogin has the user's most recent login time. And lastlogin has their second-most-recent login. Moodle seems to use the 'lastlogin' field for things like saying to the user when they log in, 'You last logged in on July 3'.

currentlogin and lastlogin both start out at 0 when a user account is newly created. The first time a user logs in, currentlogin will get populated with a date but lastlogin will remain 0. So, users with a 0 for lastlogin but a non-zero lastaccess and user_lastaccess records are actually users who have logged in exactly once.
Average of ratings: Useful (11)
In reply to Aaron Wells

Re: lastlogin / lastaccess disparity

by Nate Baxley -
Thanks Aaron! Late or not it helped answer the question for me!

Nate
In reply to Nate Baxley

Re: lastlogin / lastaccess disparity

by Michael Cohn -

You want to talk about late... I just found this conversation and it saved my sanity. Thanks!