Friday 8 April 2016

arcgis desktop - Handling user password input in ArcPy scripts?



I'm currently trying to write a script that has a username & password input which then returns some data if the user has appropriate access. The script works just fine when I hardcode my own credentials in.


The problem I have is that I don't know how to mask password input using the "Add Script" wizard. It appears there is an option to accept an Encrypted String as a parameter, which appears to be what I want, but I can't find any documentation on how to actually utilize the GPEncryptedString class within Python. When I try to extract the parameter with arcpy.getParameterAsText(), it just returns a bunch of asterisks as a string value which obviously does me no good.


I even tried just popping up my own username/password dialog, but scripts have to be ran with the "Always in Foreground" option for the arcpy.mapping.MapDocument("CURRENT") command to work properly, which constantly steals focus from my dialog.


This seems like a really simple problem, but I'm just not finding any documentation anywhere on this issue and I've now spent more time trying to figure out a way to mask password input than I spent on the actual script itself.



Answer



As of Version 10.2.1 there is now a String Hidden parameter which masks the text in the UI. This parameter does NOT encrypt. It only hides the characters from the display.


The encrypted string parameter is only for use with tools looking for an encrypted string, such as the Create ArcSDE Connection file tool. If you're passing a "regular" password to something else in your tool (non-esri that wants a password) your only option is String.


We've had internal discussions regarding the creation of a new parameter type, something like "hidden string" which would act like string, but mask the characters in the dialog. However it would send password in clear text behind the scene. At this point thats it, we've only talked about it as there hasn't been a big demand. I'd encourage you to up vote this idea: http://ideas.arcgis.com/ideaView?id=087E00000004GQSIA2


[Disclaimer: I work at Esri on the Geoprocessing Team]


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...