# Unable to swap after verifying login

**URL:** <https://forum.inductiveautomation.com/t/unable-to-swap-after-verifying-login/45553>\
**Category:** Ignition\
**Created:** [April 13, 2021, 9:35pm UTC](https://forum.inductiveautomation.com/t/unable-to-swap-after-verifying-login/45553 "2021-04-13T21:35:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [April 13, 2021, 9:35pm UTC](https://forum.inductiveautomation.com/t/unable-to-swap-after-verifying-login/45553/1 "2021-04-13T21:35:31Z")

</div>

Hello,

I have code to scan a badge from a barcode reader and login the user.

But I want every window button to call to do this, and swap to the appropriate window after.

the code for loging in is below and works off of a user csv i import

```auto
# This script was generated automatically by the navigation
# script builder. You may modify this script, but if you do,
# you will not be able to use the navigation builder to update
# this script without overwriting your changes.

password = system.gui.passwordBox("Scan Badge")

system.nav.openWindow("Main Windows/TableImport")
window = system.gui.getWindow("Main Windows/TableImport")
data = window.rootContainer.getComponent("User Table").data
system.nav.closeWindow("Main Windows/TableImport")
user_name = ""

for row in range(data.rowCount):
	index_row = data.getValueAt(row, 3)
	if index_row == password:
		user_name = data.getValueAt(row, 1)
		break

#Disables Read-Only-Mode, starts timer
system.util.setConnectionMode(3)
system.tag.writeToTag("System1/Project1/ReadModeOnly", 0)
system.tag.writeToTag("System1/Project1/TimerState", 1)
system.nav.swapTo('Powder Main')
	
success = system.security.switchUser(user_name, password)

# If the login didn't work, give input focus back to the
# username component, so that the user can try again
if not success:
	system.tag.writeToTag("System1/Project1/ReadModeOnly", 1)
	system.tag.writeToTag("System1/Project1/TimerState", 0)
	system.nav.openWindow("Nav")
	window = system.gui.getWindow("Nav")
	window.rootContainer.getComponent("Timer").value = value

```

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [April 13, 2021, 10:15pm UTC](https://forum.inductiveautomation.com/t/unable-to-swap-after-verifying-login/45553/2 "2021-04-13T22:15:58Z")

</div>

I got it to work by putting the swap to above the connect mode. But now I want it to redirect if the role should not have access
