Fanning Software Consulting

Writing a Password Widget

QUESTION: Can you show me how to write a password widget that echos the real password with asterisks as the user types?

ANSWER: The trick here is to use a text widget in which you turn the keyword Editable off and the keyword All_Events on. This way you will get each input character event in your event handler. Simply take each character as it comes in and build your password internally. But write asterisks to the text widget. In other words, only you can edit the text widget, not the user.

Here is a simple function, entitled Password, that can be used like this:

   IDL> thePassword = Password()

Here is what the program looks like on the display.

The Password program on the display.

If you call the Password program from a widget program, be sure you use the Group_Leader keyword:

   thePassword = Password(

This is the only way to insure that the Password program is a modal widget dialog.

WARNING: I'm not saying this is the most secure password program in the world. I'm just saying it is a place to start. :-)

Web Coyote's Guide to IDL Programming