I like your code, but I am on solaris, not win32. I used your while loop, but I kept getting asterisks even after I pressed return. In other words, the while loop never ended. Here's what I am using:
print " Enter your password:\n";
ReadMode 3;
while($key = ReadKey()){
$val = ord $key;
push @password, $key unless $val == 8 || $val == 13;
last if $val == 13;
print "*" unless $val == 8;
}
By the way, what does the 8 and 13 correspond to? I am sure that may have something to do with the problem. | [reply] [d/l] |
Have you tried to press the backspace key? You code works, sure, if your user never makes a typing mistake. I didn't see any handling of backspaces in your code.
| [reply] |
Okay, I've learned that ord returns the numeric ascii value of the first character of $key. But where can I find a listing of those values so I can figure out what 8 and 13 correspond to? Do ascii values remain the same across platforms?
| [reply] |
Got it! The ascii value of eight is for backspaces. And 13 is for carriage returns, but on my solaris machine, 13 was not working, so I changed 13 to 10, the value for newlines, and it worked like a charm. Thanks.
| [reply] |