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; }