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

[MacPerl] Supressing display of passwords



Greetings!

I need to get the users of a MacPerl application to authenticate 
themselves in a non-private environment.  So that others can't peek over 
the user's shoulder and see the password at it's being typed, I need to 
suppress (or otherwise obscure) the output (which normally goes to the 
screen).

I had originally though that MacPerl::Ask would support this sort of 
thing, but MPPE makes no mention.  Then I thought I could just redirect 
STDOUT to Dev:Null, but that didn't work either.  Finally I came across a 
method of intercepting the raw input stream using stty (MPPE.297), which 
I tweaked a bit to get:

---
print "Please log in...\nUsername: ";
$user = <STDIN>;
chomp $user;
print "Password: ";
`stty raw`;
while (($char = getc()) ne "\n")
{
  if ($char =~ /\w/) { $pass .= $char; } else { sleep 1; }
}
`stty sane`;

# validation of $user and $pass in here

print "\nPassword accepted!\n";
---

Works like a charm - providing the user doesn't make (or try to correct) 
a typo.

Note that "else { sleep 1; }" is optional, but it frees up CPU cycles for 
other apps to use - nice and polite if your Mac hosts other services.

I'm just wondering if anyone has any suggestions or comments on the above 
approach or code, or can offer a different approach.

Ciao.

Henry.

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