SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict Quaint's Avatar
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    TimeOut for re-authentication, only if user is inactive

    Hi all!

    I think I have an interesting question for y'all..

    What I need is a method that forces a user to re-authenticate themselves (log-in again...) after they stayed on a certain page for a certain time, but ONLY if they actually where inactive during that time! Quite possibly they needed to read a bit, or whatever so they exceeded the 5/10 minute timeout I have in mind.. But if they used their mouse, entered data or whatever, I don't want the page to time out!

    How would you deal with this?

    What I came up with so far is have a timer running in the background (using setTimeout and an infinite loop method call). I can currently reset the timer by clicking a button (I have the method for that), now I just need the proper event to keep track of user activity..

    Any suggestions?

    Quaint Tech
    - Blog on web development and web technology.

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You don't need infinite loops. Have a function that starts the timer and call it whenever you use any events that indicate activity. Something like this:
    Code Javascript:
    function startTimer() {
    window.clearTimeout(timer);
      timer = window.setTimeout(reAuth, 5000); // 5 min
    }
     
    function reAuth() {
      // re-authentication code
    }
     
    var evs = ['scroll','mousemove','mousedown','keydown'];
    for (var i = 0; i < 4; i++) {
      window['on'+evs[i]] = startTimer;
    }
    You might want to use one of the addEvent() functions people have written instead.

  3. #3
    SitePoint Addict Quaint's Avatar
    Join Date
    May 2004
    Location
    Netherlands
    Posts
    219
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice! Elegant! Much better performance indeed! Thank you

    Quaint Tech
    - Blog on web development and web technology.


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
  •