in reply to Re: Hiding password on commandline
in thread Hiding password on commandline

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.

Replies are listed 'Best First'.
Re: Re: Re: Hiding password on commandline
by Roger (Parson) on Jan 18, 2004 at 23:29 UTC
    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.

Re: Re: Re: Hiding password on commandline
by Anonymous Monk on Jan 18, 2004 at 22:48 UTC
    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?
      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.
        :-), now sign up for Monks (it's free). I think my turning point in Perl was when I joined this site. These guys are AWESOME, and we all just want to pass the knowledge along.
        Once you really learn Perl, I promise, you won't want to use any other language, and you will probably think you can solve all problems with it. Indeed, once I thought I saw a decent argument for NOT using it. A guy had an algorithm that indeed ate a lot of computation time when he emulated the c function that he had. In c the function took about 4 seconds. In Perl it took over 10 minutes to run. Ugly... but then a gent showed how to use the Inline::C module to compile that C code into a library that Perl linked to at run time and bingo.. the whole program ran in 4 seconds. I was hooked on Perl at that moment.
        JamesNC