" />
Home > Perl, Programming > Hiding your STDIN

Hiding your STDIN

Ever write a script that you have to enter a elevated users password? or even your own? Check this out.

#!/usr/bin/perl
use Term::ReadKey;
print "Please enter your username: ";
chomp(my $username = <STDIN>);
print "Please enter your password for $username: ";
ReadMode(‘noecho’);
chomp(my $password = ReadLine(0));
ReadMode(‘normal’);

#for example only. You shouldn’t print this…
print "\nYou entered $username for a username and $password for a password!!\n";
 

Using Term:ReadKey you can disable echo for STDOUT. This way no one will see your password from over your shoulder.

Popularity: 10% [?]

Categories: Perl, Programming Tags:
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.