[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Supressing display of passwords



On 19991129 0240, Chris Nandor wrote:

>>Works like a charm - providing the user doesn't make (or try to 
>>correct) a typo.
>
>If you take out the if /\w/ part, then you can accept and process
>backspaces properly.

<tests>  Well, how about that - it does too!

MPPE 297: "...[raw mode] turns off echoing and interpretation of 
characters.  In raw mode, a Perl program sees all characters entered, 
including backspace or delete characters and RETURN, as if they were part 
of the input!" -- This led me to think that if the user typed 'a' then 
'delete' then 'c' that the string would contain "a\bc" and not merely 
'c', and probably wouldn't match in subsequent tests.

Interpretation being turned off, to me, suggests that backspace and 
delete would not longer behave as expected.  Anyone else thrown by the 
wording?


>You can also check if /[\w\b]/, which allows word characters or backspace
>characters (\b in double quotes or in a character class is a backspace; in
>a regex, but outside a character class, it is a word boundary).

Ah, that's handy to know - thanks.  I didn't particularly want to lose 
the ability to screen out 'special' characters.


For those that have been following the thread, the current code snippet 
which allows the user to enter a (alphanumeric plus "_") password in the 
console window *without* echoing back to the screen, and *with* the 
ability to use the 'delete' key to correct errors, is as follows:

`stty raw`;
while (($char = getc()) ne "\n")
{
  if ($char =~ /[\w\b]/) { $pass .= $char; }
  else { sleep 1; }
}
`stty sane`;

('else { sleep 1; }' is optional, and only of value if other services are 
being hosted on the same Mac.  If you don't tell the script to sleep, it 
will hog the CPU big-time.)

Henry.

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org