Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Changing stty echo to star characters

by Frits (Novice)
on Jan 04, 2012 at 11:05 UTC ( #946223=perlquestion: print w/replies, xml ) Need Help??
Frits has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, At this moment I have my script asking for a password without the echo.

use strict; use warnings; use diagnostics; use lib '/perlmod/lib/'; use lib '/perlmod/arch/'; use lib '/tools/perl/lib/'; use lib '/usr/local/lib/perl5/5.8.8/'; use lib '/tools/perl/arch/'; use Expect; use Spreadsheet::WriteExcel; use MIME::Lite; use File::Grep qw( fgrep fmap fdo ); use Time::Local; use Net::SNMP; use Term::ANSIColor; print "login password: "; system "stty -echo"; $to_be_usered = <STDIN>; chomp $to_be_usered; system "stty echo";

What I would like to achive is that any character entered is echo-ed back to the terminal as a star character getting *******. I have tried 4 options of which none were working. Any one an idea? Regards, Frits

Replies are listed 'Best First'.
Re: Changing stty echo to star characters
by derby (Abbot) on Jan 04, 2012 at 11:46 UTC

    I don't believe the stty command has an option for this. You would need to read each character individually and echo back an asterisk accordingly. Term::Readkey makes this easy but you still need to handle edge cases like the backspace or control characters. Or you could just use IO::Prompt.

    -derby
Re: Changing stty echo to star characters
by Khen1950fx (Canon) on Jan 04, 2012 at 14:09 UTC
    Using IO::Prompt:
    #!/usr/bin/perl use strict; use warnings; use IO::Prompt; my $user = prompt "Enter username: ", -echo => "*"; my $pass = prompt "Enter password: ", -echo => "*";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://946223]
Approved by marto
help
Chatterbox?
[Discipulus]: where is vote fairy? I'm expecting a refreshing fall of XP..

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2017-06-24 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (558 votes). Check out past polls.