Simulating password entry

Richard Gaskin ambassador at fourthworld.com
Wed Aug 18 16:33:32 EDT 2004


Devin Asay wrote:
>
> I'm writing an app that simulates a network server login on Mac OS X. 
> I want the password field to behave just like normal password fields 
> in OS X; i.e., bullet characters appear in place of clear text. I've 
> sorta kinda got it working by trapping the keydown message in the 
> password field, but it's quirky. Before I spend a lot of time on this, 
> I thought I'd ask: Has anyone done this and would mind sharing a script?

A tip for use bullets across platforms:

Remember that characters in fields are automatically updated between 
platforms to account for things like mapping the Mac bullet character to 
the Windows bullet character.

So in my login screens I have a hidden field that contains just a bullet 
character, and I use that in the scripts that handle my visible entry field.

Here's a variant of such a script, borrowed largely from the MC IDE -- I 
have this in the bullet (display) field named "ftpPasswordBullet", with 
another hidden field to store the actual text named "ftpPassword":
---------------------------------------------------------

local sBullet


on tabkey
   focus on fld "ftpname"
end tabkey

on openField
   put char 1 of fld "bulletchar" into sBullet
   select the text of the target
end openField

on keyDown which
   local tpos
   put the selectedChunk into tpos
   put which into character (word 2 of tpos) to (word 4 of tpos) of 
field "ftpPassword"
   star
   select after character (word 2 of tpos) of fld "ftpPasswordBullet"
end keyDown

on deleteKey
   deleteone
end deleteKey

on backspaceKey
   deleteone
end backspaceKey

on deleteone
   put word 2 of the selectedChunk into tStart
   put word 4 of the selectedchunk into tEnd
   --
   if tStart > tEnd then
     put empty into char tEnd of fld "ftpPassword"
   else
     put empty into char tStart to tEnd of fld "ftpPassword"
   end if
   star
   select before char (tStart-1) of fld "ftpPasswordBullet"
end deleteone

on commandKeyDown pChar
   put word 2 of the selectedChunk into tStart
   put word 4 of the selectedchunk into tEnd
   --
   switch pChar
   case "x"
     cut char tstart to tEnd of fld "ftpPassword"
     star
     break
   case "v"
     select char tStart to tEnd of fld "ftpPassword"
     paste
     star
     select after character tEnd of fld "ftpPasswordBullet"
     break
   default
     pass commandKeyDown
   end switch
end commandKeyDown

on star
   local tstring
   put empty into tstring
   repeat with i = 1 to the number of characters in fld "ftpPassword"
     put sBullet after tstring
   end repeat
   put tstring into field "ftpPasswordBullet"
end star



-- 
  Richard Gaskin
  Fourth World Media Corporation
  ___________________________________________________________
  Ambassador at FourthWorld.com       http://www.FourthWorld.com


More information about the use-livecode mailing list