" />

mikerochford.com Being technical

26May/090

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: 4% [?]

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

Connect with Facebook

(required)

No trackbacks yet.