Last active
January 17, 2017 17:11
-
-
Save jberger/5023930905e05b499041ea7d2656bd0c to your computer and use it in GitHub Desktop.
Pure-perl core-only echo-off password reader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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