# switchUser function troubles

**URL:** <https://forum.inductiveautomation.com/t/switchuser-function-troubles/60285>\
**Category:** Ignition\
**Tags:** security, ignition81, scripting, vision\
**Created:** [June 2, 2022, 3:14am UTC](https://forum.inductiveautomation.com/t/switchuser-function-troubles/60285 "2022-06-02T03:14:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Valentin\_Fedotov](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@Valentin\_Fedotov](https://forum.inductiveautomation.com/u/Valentin_Fedotov)\
**Post date:** [June 2, 2022, 3:14am UTC](https://forum.inductiveautomation.com/t/switchuser-function-troubles/60285/1 "2022-06-02T03:14:21Z")

</div>

Hi everyone!

I try add custom login screen using system.security.switchUser() function on login button, the following code bellow:

```auto
uname = event.source.parent.getComponent('Username').text
pwd = event.source.parent.getComponent('Password').text
success = system.security.switchUser(uname, pwd, event)

if success:
    system.util.invokeLater(switchWin, 500)
else:
    system.gui.massageBox('Access denied. Incoreect username or password', 'Auth')

```

during login next exception appears:  
java.lang.IllegalArgumentException: Cannot create PySting with non-byte value  
\<…\>

also I’m using ActiveDirectory user source

What was done to diagnose problem:

1. audit journal - on login i have AuditStatus[0x00000000, Severity=Good, Subcore=NotSpecified], also i tried wrong creditals and there was on error code, so AD works well
2. switch login screen to default vision login - success with the same creditals
3. switch user source to internal and added user with same name and password in it - success
4. validate user source on gateway: returned correct info

How can i fix that?  
Thank you

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 2, 2022, 6:22am UTC](https://forum.inductiveautomation.com/t/switchuser-function-troubles/60285/2 "2022-06-02T06:22:40Z")

</div>

Welcome to the forum. Tip: use the `</>` code formatting button to presever indent and to apply syntax highlighting for blocks of code.

---

<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:** [June 2, 2022, 2:30pm UTC](https://forum.inductiveautomation.com/t/switchuser-function-troubles/60285/3 "2022-06-02T14:30:38Z")

</div>

> [@Valentin\_Fedotov](#):
>
> ` system.gui.massageBox('Access denied. Incoreect username or password', 'Auth')`

If this is your actual script, there's a breaking typo (should be `system.gui.messageBox`), but that doesn't explain the actual error you're seeing.

The only thing that will help diagnose that error is the actual stacktrace that you elided when you pasted it here. Please post the _full_ error message.

---

<div class="post-metadata">

**Author:** ![Valentin\_Fedotov](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@Valentin\_Fedotov](https://forum.inductiveautomation.com/u/Valentin_Fedotov)\
**Post date:** [June 5, 2022, 12:27am UTC](https://forum.inductiveautomation.com/t/switchuser-function-troubles/60285/4 "2022-06-05T00:27:15Z")

</div>

Ohh, excuse me that was a typo  
full error message bellow:

```auto
java.lang.IllegalArgumentException: Cannot create PyString with non-byte value
	at org.python.core.PyString.<init>(PyString.java:57)
	at org.python.core.PyString.<init>(PyString.java:70)
	at org.python.core.PyString.<init>(PyString.java:74)
	at org.python.core.Py.newString(Py.java:647)
	at com.inductiveautomation.factorypmi.application.script.builtin.SecurityUtilities.rolesToTuple(SecurityUtilities.java:293)
	at com.inductiveautomation.factorypmi.application.script.builtin.SecurityUtilities.login(SecurityUtilities.java:81)
	at com.inductiveautomation.factorypmi.application.script.builtin.SecurityUtilities.switchUser(SecurityUtilities.java:102)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:188)
	at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction. __call__ (ScriptManager.java:524)
	at org.python.core.PyObject. __call__ (PyObject.java:497)
	at org.python.core.PyObject. __call__ (PyObject.java:501)
	at org.python.pycode._pyx23.f$0(<event:actionPerformed>:32)
	at org.python.pycode._pyx23.call_function(<event:actionPerformed>)
	at org.python.core.PyTableCode.call(PyTableCode.java:171)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1614)
	at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:782)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:206)
	at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:297)
	at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:57)
	at com.sun.proxy.$Proxy52.actionPerformed(Unknown Source)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at java.desktop/javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.desktop/java.awt.Component.processMouseEvent(Unknown Source)
	at java.desktop/javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.desktop/java.awt.Component.processEvent(Unknown Source)
	at java.desktop/java.awt.Container.processEvent(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)

Ignition v(Dev Version)
Java: Azul Systems, Inc. 11.0.7

```

---

<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:** [June 6, 2022, 2:24pm UTC](https://forum.inductiveautomation.com/t/switchuser-function-troubles/60285/5 "2022-06-06T14:24:36Z")

</div>

This is a bug that’s fixed in 8.1.2.

I can’t tell what version you’re using, but it looks like a (very old) nightly. You should update to the latest stable 8.1 release as soon as possible.
