The #1 simplest, easiest, and fastest solution to masking characters in a
field is by switching the font to a masked font.  This is incredibally
simple as you only need one character - a star, dot (if you are old-school
Mac or new-school Windows), or other character, set as the "unknown" (-1)
character.  It will automatically be used for any undefined character in the
font.  Undefine everything, and it's all masked.  (Interesting note - bad,
bad things happen if you do not have the #9 glyph available.  Or maybe you
have to have at least /one/ glyph in the font.  Either way...)

I've even done the work for you; see the attached file for the font
definition files and example code.

        http://www.marginsoftware.com/attachments/MaskedFont.zip

Yeah, it's not a real attachment... ;)  And though my slogan is
"re-inventing the wheel, every time"... if you can do it cheaply, all the
better.

        - Matthew

P.s. Yes, I know the size of the font is rather... large.  But hey, most
users don't enter 11-digit passwords, no matter how much they /should/. ;)
Also, I would prevent copying out of a password field - pasting in is fine.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Matt
Graham
Sent: Monday, May 17, 2004 7:38 AM
To: Palm Developer Forum
Subject: Re: Masking text in a field

Dana Long wrote:
> My application has a log in screen and requires the option of masking 
> the password field. Since I see no way of getting this behaviour for 
> free from a Field object, I've gone down the road of intercepting the 
> keydown event, storing the character in an array, replacing the 
> character with a '*' like this: eventP->data.keyDown.chr = '*' and 
> returning false so the system updates the field.
> 
> This works great until the user puts the insertion point somewhere 
> other than the end of the text and hits  backspace or enters new text 
> or highlights text and pastes text and... well the list seems to keep 
> growing as I figure out how to deal with each user action.
> 
> I feel like I'm reinventing the wheel here (and so far my wheel is 
> less than round...) Is there a better way?

Not really.  Unfortunately, this seems to be a wheel that needs to be
reinvented.  My suggestion is whatever you do, make it easy to use next time
you need it.  Here are some previous suggestions from this group:

1) Disable the most disruptive feature. Do you need to allow the user to
copy and paste?  You can force the cursor to the end of the field and allow
only adding to or removing from the end.  IMO, this is the easiest
  as how often are people doing anything other than typing in their
password?

2) Duplicate all normal field functionality for your password field. 
This requires a lot of work, but if you can make it reusable, it's easy next
time you need it.

3) create a font w/ all '*' and set a regular field to use it.  This is not
my favorite solution (admittedly b/c I don't know how to do it) but it may
work for you.

--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to