Skip to content

Instantly share code, notes, and snippets.

@jberger
Last active January 17, 2017 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jberger/5023930905e05b499041ea7d2656bd0c to your computer and use it in GitHub Desktop.
Save jberger/5023930905e05b499041ea7d2656bd0c to your computer and use it in GitHub Desktop.
Pure-perl core-only echo-off password reader
use Mojo::Base -strict;
# pure perl echo-off password reader
use POSIX qw(:termios_h);
sub read_pass {
my $term = POSIX::Termios->new;
my $fd = fileno(STDIN);
$term->getattr($fd);
my $oterm = $term->getlflag;
$term->setlflag($oterm & ~ECHO | ECHONL);
$term->setattr($fd, TCSANOW);
chomp(my $pass = <STDIN>);
$term->setlflag($oterm);
$term->setattr($fd, TCSANOW);
return $pass;
}
say "Hello, please input your password";
my $pass = read_pass;
say "Thank you, I got <<$pass>>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment