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

StackOverflow https://stackoverflow.com/questions/22247611

  •  10-06-2023
  •  | 
  •  

Question

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?

Was it helpful?

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.

OTHER TIPS

You are correct when your say the ""ask password"" allows you to create a dialog box that lets a user enter there password that is in turn masked by asterisks.

Craigs post above is a great way of solving this question, but it is also possible via the following method-

If you wish to apply the same masking to an input field, you should be able to do this by first importing an image into livecode which will be used to mask characters in a field (e.g. bullet). Then, within the script of a field, you would place something like-

on textChanged
   repeat with x = 1 to the number of chars of me
   set the imageSource of char x of me to 12643
   end repeat
end textChanged

Where the imageSource is the ID of the imported image

What happens here is that the textChange message is called everytime the contents of the field change. We are then looping through the characters of the field and setting the imageSource of each character to our imported mask image."

Just so. Neil's method has the advantage of being able to access the field text directly, since it is essentially intact, just sort of morphed into "covering" chars. In other words, you can still simply:

answer field "yourField"

or

delete word 2 of fld "yourField"

instead of my slightly more distant:

answer the hiddentext of fld "yourField"

and, to modify the text as above would require a couple of lines of code.

Note Once you have a nice bullet shaped image, the imageSource method is just better. Much easier to manage...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top