Search code examples
livecode

How do I mask a users input (e.g. password) within a LiveCode field?


I am looking to create a field in LiveCode that hides a users input (e.g. with bullets or asterisk symbols)

I know that you can ask a user via pop up dialog with -

ask password "enter your password"

Is there a way to do it directly to a LiveCode field?


Solution

  • My favorite way is to populate a custom property of the field with the clear text, mapped char for char with an asterisk, say, in the field itself. As a simple test, make a field, and place this into its script

    on keydown var
       set  the hiddentext of me to the hiddentext of me & var
       put "*" after me
    end keydown
    

    In a button, you can:

    on mouseUp
    answer the hiddenText of field "yourField"
    end mouseUp
    

    Now this does not handle the delete key, but that is simple to fix, and I hope you get the idea.