I tried one of the perl modules, and it didn't work too well. Anyway, there was an example that I took from the camel book, plus stealing stuff from the module that didn't work the way I wanted it to. The result works on solaris. I think I tried it on Windows but I don't remember. (project put on hold temporarily.) I also haven't spent the time to make this particularly robust.
#!/usr/bin/perl -w use strict; package GetPassword; use Carp; our @ISA = qw(Exporter); our $VERSION = 1.001; my $get_rid_of_warning = $VERSION; our @EXPORT = qw( Get_Password ); sub Get_Password { my $flush = $|; $| = 1; # flush output to screen byte by byte my $opt = shift || ""; $opt = substr $opt,0,1; my ($bs, $ws, $bullet) = ("\b", " ", $opt); ($bs, $ws, $bullet) = ("", "", "") unless $opt; my $pass = ""; while (1) { my $ch = getone(); # Return character, end of getting password $ch =~ /[\r\n]/ && do { print "\n"; $| = $flush; # return to previous setting return $pass; }; # Backspace/delete key entered $ch =~ /[\b\x7F]/ && do { if (length ($pass) > 0) { chop $pass; print "$bs$ws$bs"; } next; }; # Warn for non-ascii characters if (ord($ch) < 32) { print "\7"; next; }; # Valid password character enetered $pass .= $ch; print $bullet; } } # ==================================================================== +======== # Terminal I/O program to get un-echoed unbuffered input # # Take from the Camel Book (3rd edition) # (Programming Perl, Larry Wall, O'Reilly), p.906 # ==================================================================== +======== BEGIN { use POSIX ":termios_h"; my ($term, $oterm, $echo, $noecho, $fd_stdin); $fd_stdin = fileno(STDIN); $term = POSIX::Termios->new(); $term->getattr($fd_stdin); $oterm = $term->getlflag(); $echo = ECHO | ECHOK | ICANON; $noecho = $oterm & ~$echo; sub cbreak { $term->setlflag($noecho); $term->setcc(VTIME, 1); $term->setattr($fd_stdin, TCSANOW); } sub cooked { $term->setlflag($oterm); $term->setcc(VTIME,0); $term->setattr($fd_stdin, TCSANOW); } sub getone { my $key = ""; cbreak(); sysread(STDIN, $key, 1); cooked(); return $key; } } END { cooked() } 1

In reply to Re: Hiding password on commandline by Sandy
in thread Hiding password on commandline by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.