Unix-Login
view release on metacpan or search on metacpan
}
}
# While loop
my $success = 0;
for (my $i=0; $i < $conf{attempts}; $i++) {
print OUTPUT $banner; # /etc/issue
if ($conf{sameuser}) {
$logintry = getpwuid($<)
|| croak "Unidentifiable user running process";
} else {
do {
print OUTPUT $conf{login};
$logintry = <INPUT>;
unless ($logintry) { # catch ^D
sttyexit if $conf{failexit};
return;
}
$logintry =~ s/\s+//g; # catch " "
This is a simple yet flexible module that provides a Unix-esque login
prompt w/ password validation. This is useful in custom applications
that need to validate the username/password of the person using the app.
The above example is pretty much all you'll ever need (and all this
module provides). Here are some specifics on the function provided:
=head2 login(option => value, option => value)
This prompts for the username and password and tries to validate
the login. On success, it returns the same thing that getpwuid()
does: the username in a scalar context, or the passwd struct as
an array in a list context. It returns undef on failure.
You can pass it an optional set of parameters. These will specify
options for that login prompt only. The parameters and their default
values are:
attempts Max login attempts [3]
failmesg Print this on failure ["Login incorrect\n"]
failsleep And sleep for this many seconds [3]
execshell => 1);
my(@pwent) = $ul->login || exit 1;
This will validate our login, clear our environment and reset it, then
exec the shell as a login shell just like a real life Unix login.
login(option => value, option => value)
This prompts for the username and password and tries to validate the
login. On success, it returns the same thing that getpwuid() does: the
username in a scalar context, or the passwd struct as a list in a list
context. It returns undef on failure.
Just like new(), you can pass it an optional set of parameters. These
will specify options for that login prompt only. As such, you can create
a fully-customized login screen from the function-oriented calling form:
use Unix::Login qw(login);
my(@pwent) = login(login => "User: ", password => "Pass: ")
( run in 0.258 second using v1.01-cache-2.11-cpan-8d75d55dd25 )