Page 1 of 1

Security: Auto log out: Inactivity Period

Posted: Mon Feb 20, 2017 12:22 pm
by kkwon2
Can the auto logout inactivity period be changed at runtime?

Re: Security: Auto log out: Inactivity Period

Posted: Wed Feb 22, 2017 3:58 am
by Lars
As fas as I know its not possible. But here's a small example how you can do your own log out function with your own tag for seconds before auto logout.
It uses the mouse position, and that works even if you dont have a mouse attached.

private static System.Windows.Forms.Timer _timer;
private int _mouseX = -1;
private int _mouseY = -1;
private int _mouseMoved;

private void TimerTick(Object sender, EventArgs e)
{
var x = System.Windows.Forms.Control.MousePosition.X;
var y = System.Windows.Forms.Control.MousePosition.Y;

if( ( Math.Abs(_mouseX-x) > 5 ) || ( Math.Abs(_mouseY-y) > 5 ) )
{
_mouseMoved=0;
}
else
{
_mouseMoved++;

var inactivityTimeout = Globals.Tags.System_InactivityTimeBeforeLogout.Value * 60;

if((inactivityTimeout>0) && (_mouseMoved > inactivityTimeout))
{
Globals.Security.Logout();
}
}
_mouseX = x;
_mouseY = y;
}

void Scriptmodule_Created(System.Object sender, System.EventArgs e)
{
// Set up timer that monitors if the mouse has moved
_timer = new System.Windows.Forms.Timer {Interval = 1000};
_timer.Tick += TimerTick;
_timer.Enabled = true;
}

Good luck :)