setting up password fields
Dave Cragg
dcragg at lacscentre.co.uk
Fri Mar 21 20:34:02 EST 2003
At 12:39 pm -0800 21/3/03, Chris Sheffield wrote:
>I know this one has been discussed a while back. I
>found some posts in an old archive, but I was
>wondering if anyone has a better (newer) way of
>setting up a regular field to accept a password entry
>(i.e. put a '*' in place of each character). I tried
>some code from an old archive something like:
>
>on keydown whichKey
> global thisPassword
> put whichKey after thisPassword
> put "*" after field "passwordField"
>end keyDown
>
>But this doesn't quite work. If the user has to
>modify what he's typed, or if he highlights the entire
>password, deletes it, and starts over, the value in
>thisPassword just keeps building on itself.
Here are some scripts I use for this. In this case, the "real" text
is stored in a custom property instead of a global. It takes account
of cases where the insertion pont is not at the end of the field and
when there is a selection. But you would also need to decide whether
to allow pasting/cutting in the field, and if so, how to handle it.
(I disallow it.)
on keyDown pChar
if pChar is in "-1234567890abcdefghijklmnopqrstuvwxyz" then ##or whatever
put word 2 of the selectedChunk into tCh1
put word 4 of the selectedChunk into tCh2
put the cpPassText of me into tPassText
if tCh1 > tCh2 then
put "*" after char tCh2 of me
put pChar after char tCh2 of tPassText
else
delete char tCh1 to tCh2 of me
delete char tCh1 to tCh2 of tPasstext
put "*" after char tCh1 -1 of me
put pChar after char tCh1 -1 of tPasstext
end if
set the cpPassText of me to tPassText
else
beep
end if
end keyDown
on deleteKey
put word 2 of the selectedChunk into tCh1
put word 4 of the selectedChunk into tCh2
put the cpPassText of me into tPassText
if tCh1 > tCh2 then
delete char tCh1 of me
delete char tCh1 of tPassText
else
delete char tCh1 to tch2 of me
delete char tCh1 to tch2 of tPassText
end if
set the cpPassText of me to tPassText
end deleteKey
on backspaceKey
put word 2 of the selectedChunk into tCh1
put word 4 of the selectedChunk into tCh2
put the cpPassText of me into tPassText
if tCh1 > tCh2 then
delete char tCh2 of me
delete char tCh2 of tPassText
else
delete char tCh1 to tch2 of me
delete char tCh1 to tch2 of tPassText
end if
set the cpPassText of me to tPassText
end backspaceKey
Cheers
Dave
More information about the use-livecode
mailing list