#!/usr/bin/perl -w
use strict;
my $username = shift;
my $password = shift;
do_something($username,$password);
sub do_something {
my ($user,$pass) = @_;
print "USER: $user\nPASS: $pass\n\n";
}
####
#!/usr/bin/perl -w
use strict;
my ($user, $pass) = get_password ();
do_something ($user,$pass);
sub do_something {
my ($user,$pass) = @_;
print "\nUSER: $user\nPASS: $pass\n";
}
sub get_password {
$ENV{'PATH'} = "/bin:/usr/bin";
print "Username: ";
my $username = ;
chomp $username;
print "Password: ";
system ('stty -echo');
my $password = ;
system ('stty echo');
print "\n\n";
return ($username,$password);
}
####
#!/usr/bin/perl -w
use strict;
my ($user,$pass) = get_secret();
do_something($user,$pass) if ($user) && ($pass);
sub do_something {
my ($user,$pass) = @_;
print "USER: $user\nPASS: $pass\n\n";
}
sub get_secret {
my $config = $ENV{'HOME'} . '/.passwd3';
if (-e $config) {
my ($pass,$user);
my $perms = (stat ($config))[2] & 07777;
die "ERROR: File permissions not 700.\n" unless $perms == 0700;
open INP, $config or die "ERROR: Couldn't open file: $!\n";
chomp ($user = );
chomp ($pass = );
close(INP);
return($user,$pass);
}else{
die "ERROR: No config file.\n";
}
}