|
password behavior
> Has anybody successfully implemented the password field?? I need to display
> the password in the form of asterisks as the user types the password.
There are several such scripts floating around, but most of them have their
problems. Here is a cross platform behavior that works on a field sprite. Watch
for line breaks...
-- password text bh
----------------------------------------------------------------------
property spriteNum
property ppasswd
property pmaskchar
property pfieldmem
property pmodified
property ploginbutton
property pcancelbutton
on beginSprite me
ppasswd = ""
if the platform contains "Windows" then
pmaskchar = "*"
else
pmaskchar = numtochar(165)
end if
pfieldmem = the number of the member of sprite spriteNum
pmodified = 0
ppasswd = ""
-- put your sprite numbers here
ploginbutton = 10
pcancelbutton = 11
end
on keyDown me
case the keyCode of
36 : -- ENTER
sendSprite(ploginbutton, #mouseDown)
updateStage
sendSprite(ploginbutton, #mouseUp)
53 : -- ESCAPE
sendSprite(pcancelbutton, #mouseDown)
updateStage
sendSprite(pcancelbutton, #mouseUp)
51 : -- BACKSPACE
if the selstart < the selend OR the selstart then
ch1 = the selstart + (the selstart < the selend)
ch2 = the selend
delete char ch1 to ch2 of ppasswd
the selstart = the selstart - (the selstart = the selend)
the selend = the selstart
end if
48, 123, 124, 125, 126 :
pass
117 :
ch1 = the selstart + 1
ch2 = the selend + (the selstart = the selend)
delete char ch1 to ch2 of ppasswd
otherwise :
n = length(ppasswd)
ppasswd = chars(ppasswd, 1, the selstart)
ppasswd = ppasswd & the key & chars(ppasswd, the selend + 1, n)
pmodified = 1
end case
pad = ""
repeat with i = the number of chars of ppasswd down to 1
pad = pad & pmaskchar
end repeat
put pad into field pfieldmem
setCaret
end
on setCaret
if pmodified then
y = the selStart + 1
the selEnd = y
the selStart = y
end if
pmodified = 0
end
on getPassword me
return ppasswd
end
___________________________________________________________________________
k e n p r a t Blackstone Multimedia Corporation
|