# Keep users from logging in on multiple devices

**URL:** <https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [September 13, 2022, 2:56pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013 "2022-09-13T14:56:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_M](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Daniel\_M](https://forum.inductiveautomation.com/u/Daniel_M)\
**Post date:** [September 13, 2022, 2:56pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/1 "2022-09-13T14:56:58Z")

</div>

Is there a way in Perspective to keep users from logging in on multiple devices at once? I have a specification where “The SCADA client shall prohibit simultaneous logins with the same user account.”

I’m not sure how this could be implemented. Is there a subsystem in Ignition that tracks who’s currently logged in in the built-in IDP?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 13, 2022, 3:09pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/2 "2022-09-13T15:09:54Z")

</div>

If there isn’t a built in system, I guess you could use session startup and shutdown events to add/remove the current user to a list that you’d store in a tag, and instantly log out the user if he’s already in the list…  
It’s ‘a bit’ dirty, but if you can’t find a better option…

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 13, 2022, 3:14pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/3 "2022-09-13T15:14:40Z")

</div>

For clarification, do you need to log out _other_ sessions, or do you need to prevent this attempt at logging in?

---

<div class="post-metadata">

**Author:** ![Daniel\_M](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Daniel\_M](https://forum.inductiveautomation.com/u/Daniel_M)\
**Post date:** [September 13, 2022, 3:20pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/5 "2022-09-13T15:20:27Z")

</div>

> [@Daniel\_M](#):
>
> The specification doesn’t specify so at this point we can do whatever is easiest to implement. If I want to be really nice I could do both and have a message box with a couple buttons to let the user choose. But that’s not specified, so I’d go with the path of least developmental resistance.

The specification doesn’t specify so at this point we can do whatever is easiest to implement. If I want to be really nice I could do both and have a message box with a couple buttons to let the user choose. But that’s not specified, so I’d go with the path of least developmental resistance.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 13, 2022, 3:27pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/6 "2022-09-13T15:27:27Z")

</div>

As long as it is acceptable to logout any _other_ session which is attached to the user currently attempting to login, this should be pretty easy with a change script on `session.auth.user.username`. You could make your script something like this:

```auto
# find all sessions which are using this user's username
for session in system.perspective.getSessionInfo(currentValue.value):
    # and log them all out
    system.perspective.logout(sessionId=session["id"])

```

---

<div class="post-metadata">

**Author:** ![Daniel\_M](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Daniel\_M](https://forum.inductiveautomation.com/u/Daniel_M)\
**Post date:** [September 13, 2022, 3:47pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/7 "2022-09-13T15:47:08Z")

</div>

Great, thank you!

---

<div class="post-metadata">

**Author:** ![Daniel\_M](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Daniel\_M](https://forum.inductiveautomation.com/u/Daniel_M)\
**Post date:** [September 13, 2022, 3:58pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/8 "2022-09-13T15:58:31Z")

</div>

Actually it doesn’t seem to work for me. I can still have many users open.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 13, 2022, 4:23pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/9 "2022-09-13T16:23:32Z")

</div>

What do you see if you log `currentValue.value` for these sessions?

Update: It looks like that property doesn’t technically “change” if the project requires authentication because the property initializes as the username, instead of initializing as some other value and then changing to the username. Let me see if I can do it some other way.

---

<div class="post-metadata">

**Author:** ![Daniel\_M](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Daniel\_M](https://forum.inductiveautomation.com/u/Daniel_M)\
**Post date:** [September 13, 2022, 4:37pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/10 "2022-09-13T16:37:30Z")

</div>

I conducted some research. And I made a few interesting discoveries (well, to me anyway). I created duplicate logins three different ways to the session. The first was two tabs logged into the same account on the same web browser (edge). Then I logged into the account on a different web browser. And then I logged into the project on a completely different computer (on the same network, of course).

(see images below)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/0/909fe6c12255d640847bc8173433834f8435914f.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/0/a00367dabd835416951463d2cd0fc7f4e8ecda89.png)

It seems that logins from different PCs and different web browsers count as different sessions, but logins on the same web browser (different tabs) count as the same session, but have different IDs.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 13, 2022, 4:55pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/11 "2022-09-13T16:55:43Z")

</div>

There’s a complicated nesting hierarchy.  
One session can have many pages (in a browser, each tab will be a distinct page, with its own ID).  
Each page can have many views.  
Each view can have many components.

---

<div class="post-metadata">

**Author:** ![Daniel\_M](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Daniel\_M](https://forum.inductiveautomation.com/u/Daniel_M)\
**Post date:** [September 13, 2022, 5:28pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/12 "2022-09-13T17:28:59Z")

</div>

I wonder if it should instead look to see if the username matches and session ID is different. This interface doesn’t open new tabs so it should keep the same session for each login.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 13, 2022, 5:56pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/13 "2022-09-13T17:56:44Z")

</div>

> [@Daniel\_M](#):
>
> I have a specification where “The SCADA client shall prohibit simultaneous logins with the same user account.”

There's not really a "clean" way to do this through Perspective, because we're trying to use the session to solve an IdP problem; the Identity Provider should be preventing the user from logging in a second time, or managing previous logins.

One solution:

- create a new custom session property: `session_limiter`.
- Bind `session_limiter` with the following expression binding: `{this.props.auth.user.userName} != null` and Script transform:

```auto
def transform(self, value, quality, timestamp):
	for session in system.perspective.getSessionInfo(usernameFilter=self.props.auth.user.userName):
		if (session["sessionScope"] != "designer") and session["id"] != self.props.id:
			system.perspective.closeSession("You are limited to only one session at a time.", session["id"])
			return True # denotes a session was closed during execution of the binding
	return False # denotes no action was taken

```

If you go this route, I highly recommend requiring re-authentication in the Project Properties, otherwise you'll likely encounter users unintentionally re-authenticating as the previous user. In the menu bar, see `Project > Project Properties > Project > General`

 ![Screen Shot 2022-09-13 at 10.54.02 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/e/0e622c76211e6d4de09ba75c8ecc6b3dd9fe2088.png)

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 13, 2022, 6:09pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/14 "2022-09-13T18:09:04Z")

</div>

A proposed secondary solution, assuming the project will always require authentication:

- Configure a Session Startup Event, and supply the following code:

```auto
def onStartup(session):
	for session_obj in system.perspective.getSessionInfo(usernameFilter=session.props.auth.user.userName):
		if (session_obj["sessionScope"] != "designer") and session_obj["id"] != session.props.id:
			system.perspective.closeSession("You are limited to one session at a time.", sessionId=session_obj["id"])

```

---

<div class="post-metadata">

**Author:** ![Daniel\_M](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Daniel\_M](https://forum.inductiveautomation.com/u/Daniel_M)\
**Post date:** [September 13, 2022, 6:25pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/15 "2022-09-13T18:25:28Z")

</div>

This solution worked! This is excellent, thank you. I wasn’t able to get the onStartup solution to work, but the primary solution works as intended.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [September 13, 2022, 6:37pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/16 "2022-09-13T18:37:19Z")

</div>

> [@Daniel\_M](#):
>
> I wasn’t able to get the onStartup solution to work, but the primary solution works as intended.

Ah, there was a typo. I'll update it.

---

<div class="post-metadata">

**Author:** ![Daniel\_M](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Daniel\_M](https://forum.inductiveautomation.com/u/Daniel_M)\
**Post date:** [September 14, 2022, 11:39am UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/17 "2022-09-14T11:39:51Z")

</div>

Great, thank you! This solution seems to work even better. I was having issues with the previous one, though I’m not sure if I accidentally changed something with it.

---

<div class="post-metadata">

**Author:** ![Eagel007](https://avatars.discourse-cdn.com/v4/letter/e/7bcc69/32.png) [@Eagel007](https://forum.inductiveautomation.com/u/Eagel007)\
**Post date:** [February 12, 2024, 4:01pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/18 "2024-02-12T16:01:06Z")

</div>

It leads to this page. and we really dont want clients to access this page.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/7/97edd3dadba4419ed8c9dbb03ed847aee31b88ea.png)

can we instead perform logout? I was unable to do so.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [February 12, 2024, 4:26pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/19 "2024-02-12T16:26:12Z")

</div>

What did you try and what happened ?

---

<div class="post-metadata">

**Author:** ![Eagel007](https://avatars.discourse-cdn.com/v4/letter/e/7bcc69/32.png) [@Eagel007](https://forum.inductiveautomation.com/u/Eagel007)\
**Post date:** [February 12, 2024, 4:28pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/20 "2024-02-12T16:28:06Z")

</div>

i used above mentioned script.  
def onStartup(session):  
for session\_obj in system.perspective.getSessionInfo(usernameFilter=session.props.auth.user.userName):  
if (session\_obj["sessionScope"] != "designer") and session\_obj["id"] != session.props.id:  
system.perspective.closeSession("You are limited to one session at a time.", sessionId=session\_obj["id"])  
**-same code as above**  
and it brought to this page when i tried to login with same username on another browser.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [February 12, 2024, 4:30pm UTC](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013/21 "2024-02-12T16:30:41Z")

</div>

So you were unable to do something that you didn't try ?

[https://docs.inductiveautomation.com/display/DOC81/system.perspective.logout](https://docs.inductiveautomation.com/display/DOC81/system.perspective.logout)

ps: Use the code formatting tool when posting code.

[Next page](https://forum.inductiveautomation.com/t/keep-users-from-logging-in-on-multiple-devices/64013.md?page=2)
