Login/logout scripts, auto logout

Hi,
I have two questions about security configuration:

  1. can I program a script that executes when a user logs in and another one that executes when a user logs out? I cannot find the place where such a script may be configured, or shall I program a script on a tag change event, where that tag is via expression linked to the [System]Client/User/Username tag value?

  2. Is there a way to configure an auto-logout time for each user or shall I program a background function that execute the logout when time expires?

Thanks in advance, regards

In the designers project browser, under Project --> Scripts --> Client Event Scripts there are two places to write scripting that you want: Startup and Shutdown. These scripts will run when a client is started and when a client is shut down respectively.

For logging out after a specific amount of time of inactivity, look at the Timer section of the Client Event Scripts. here you can write a script that runs every so often to check how long the client has been inactive for. Something like this:

[code]# Check to see how long since any keyboard or mouse activity from the user and

if longer than 5 minutes then logout.

if system.util.getInactivitySeconds() > 300:
system.security.logout()[/code]

Thanks duffanator. Maybe I was not clear about my problem: you say

I'll explain further: I don't need scripts to be executed when the client starts and/or stops. I need to program scripts associated with user login and user logout events. For example I'm the user "boss", I log in as "boss" and just when I log in as "boss" I want my client to execute a piece of python script; on the other side when I "boss" log out I want my client to execute some other piece of python script.
As far as the time expiration is concerned your suggestion could be ok, provided that I don't need to measure exactly the "login time", i.e. the time since I did my login, and not my inactivity time during work with my Ignition client.

Yeah, that’s what the startup and shutdown scripts do. They will run on login and logout, I think the only time they don’t run is if you SWITCH users. But if you log out then the shutdown script will run and if you login then the startup script will run.

I guess if you want to auto logoff after a set amount of time after a login then you could write the current time to a client tag in the startup script and check the elapsed time with a timer script every so often. If the elapsed time is greater than whatever time delta that you want then you can auto logoff. I’m not sure why you’d want to do this though, it could get extremely frustrating if someone is in the middle of doing something and the client suddenly logs out.

1 Like

Yes, you are right duffanator, I didn't realize that, thanks.

That is also true, and that's why I never saw the startup/shutdown events working when users login/logout: in my application I never go through a logout/login procedure. Instead logging out I switch to a "BasicUser" with almost no roles (that is also the user specified for the auto-login in the project properties) , so that the SCADA is there and live, but no one may do anything. I think that I will attach an event handler to the tag change event of a tag derived from [System]Client/User/Username and there I will program the commands I need when users login/logout.

Thanks again, regards

1 Like