Ignition - Prompt for password on action, but don't log in

Hello, I am trying to implement a system where certain actions require a password entry. The intent is to force the user to enter a password every time certain actions are requested, as a form of confirmation.

Is it possible to hook into the security system or confirmation dialog, such that I can automatically bring up a custom window which does the security validation and performs the action, the way that the default confirmation window does?

Make your own popup window with a password field, then assemble the current username (from the system/client tag, or the system function) and pass it to system.security.validateUser - if it returns True, then you know the password was correct, and can continue your logic.

1 Like

What @PGriffith said. And if you also need to check roles, you can do both at once with system.security.getUserRoles. Something like:

reqRole = 'Role user must have'
currentUser = system.security.getUsername()
username = usernameField.text
password = passwordField.text
roles = system.security.getUserRoles(username, password)
if roles == None:
	# Respond to failed validation.
elif reqRole in roles:
	# Respond to successful validation with required role.
	pass
	# Login validated user if credentials don't match current user.
	if username.lower() != currentUser.lower():
		# Login user.
		system.security.switchUser(username, password)
else:
	# Respond to successful validation without required role.
1 Like

Thanks for your response. How would this work for e.g. a multistate button. I did not have luck using the propertyChange event (I couldn’t stop the ControlValue change)

I assume from your response it’s not possible to override the default confirmation window?

Add a custom property to use in place of the Control Value. My example uses ‘WriteValue’ as the custom property.

In the propertyChange Event:

if event.propertyName == 'controlValue' and event.newValue != event.source.WriteValue:
	
	currentUser = system.security.getUsername()
	password = system.gui.passwordBox("Confirm Password")
	valid = system.security.validateUser(currentUser, password)
		
	if valid:
		event.source.WriteValue = event.newValue
	else:
		event.source.controlValue = event.source.WriteValue
		system.gui.errorBox("Incorrect password")

Window attached.
Multistate_Password_2020-01-16_0816.zip (4.9 KB)

1 Like

Thank you for your help!