Here is a subroutine for just that purpose. In this case, it asks for a password twice and returns undef if they didn't match.
sub get_passwd_on_console { use POSIX; print "Password: "; # Set the terminal to "no echo" mode for reading the passphrase 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; $term->setlflag($noecho); $term->setattr($fd_stdin, TCSANOW); my $passwd = <>; chomp $passwd; print "\n"; print "Password (retype): "; my $passwd2 = <>; chomp $passwd2; print "\n"; # Set the terminal back $term->setlflag($echo); $term->setattr($fd_stdin, TCSANOW); return ($passwd eq $passwd2) ? $passwd : undef; }
In reply to Re: Accepting Password from user
by hardburn
in thread Accepting Password from user
by TheYoungMonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |