The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Authen::Prepare - Prepare a set of authentication credentials

VERSION

This document describes Authen::Prepare version 0.05

SYNOPSIS

    use Authen::Prepare;

    # Prompt for the hostname, username, and password
    my $authen = Authen::Prepare->new();

    # The '%cred' hash now has the keys 'hostname', 'username', 
    # and 'password'
    my %cred = $authen->credentials();

    # Specify hostname as 'localhost'. Prompt for username and password
    my $authen = Authen::Prepare->new( { hostname => 'localhost' } );
    my %cred = $authen->credentials();

    # Specify a hostname as 'localhost', username as 'testuser', and a 
    # password file as '~/.authrc'. No prompting will occur if the 
    # hostname and username are found in the password file.
    my $authen = Authen::Prepare->new( 
        { 
            hostname => 'localhost',
            username => 'testuser',
            passfile => '~/.authrc',
        } 
    );

    my %cred = $authen->credentials();

    # Assuming %opt contains the set of command-line arguments, specify 
    # the hostname, username, and password file with the command-line 
    # arguments or with environment variables as a fallback.  
    my $authen = Authen::Prepare->new( 
        { 
            hostname => $opt{hostname} || $ENV{MY_HOSTNAME},
            username => $opt{username} || $ENV{MY_USERNAME},
            passfile => $opt{passfile} || $ENV{MY_PASSFILE},
        } 
    );

    my %cred = $authen->credentials();
  
    # The '%cred' hash can be used to authenticate in scripts or modules with
    # the stored hostname, username, and password
    $foo->authenticate(%cred);
  

DESCRIPTION

Authen::Prepare sets up authentication credentials for a specific hostname, username, and password using a combination of stored information and user prompts. These credentials can be used in other scripts or modules that require authentication information. Using this module allows these other scripts to be flexible in their usage of authentication information without recoding user prompts or storing passwords in the code.

The simplest use of this module is to create the initial object it with no arguments; the credentials will be built from a set of user prompts.

A more full-featured use of this module is to specify all authentication information ahead of time using a password file and command-line arguments or environment variables. The initial object can then be created with three named arguments (hostname, username, and passfile) and the credentials for the specified hostname and username will be extracted from the password file. This allows the calling script to be used in an automated environment.

Any combination of the named arguments can be provided; the user will be prompted for any missing information.

Password File

The password file must not have any group or world permissions in order to be usable by this module. Each line of the password file should contain the hostname, username, and password separated by a colon.

Wildcards are supported in the hostname field only. This allows a default host to be specified.

Comments may be added by prefixing a line with the '#' character. (Inline comments are not supported at this time.)

NOTE: The password file is read from top to bottom so only the first match will be returned.

  Example:

  # this is a comment
  hostname1:username1:password1
  hostname2:username2:password2
  host*:username:password
  # default hostname
  *:username:password

INTERFACE

new()
new(\%options)

The constructor 'new' creates the initial object and sets up the cached credentials for a hostname, username, and password file. If the hostname, username, or passfile accessors are not specified, the user will be prompted.

Any of the accessors (see below) can be used as named arguments.

  Example:
  # Prompt for everything
  my $authen = Authen::Prepare->new();

  # Prompt for hostname. Use specified username and passfile
  my $authen = Authen::Prepare->new(
    { username => $username, passfile => $passfile });

  # Prompt for username. Use specified hostname and passfile
  my $authen = Authen::Prepare->new(
    { hostname => $hostname, passfile => $passfile });

  # Prompt for password. Use specified hostname and username
  my $authen = Authen::Prepare->new(
    { hostname => $hostname, username => $username });
credentials()

The 'credentials' method returns the cached credentials in the form of a hash with the following keys:

  * hostname
  * username
  * password

Note: This method is context sensitive: in scalar context, it will return a hash reference.

Accessors

hostname()
hostname(HOSTNAME)

Get or set the hostname.

username()
username(USERNAME)

Get or set the username.

passfile()
passfile(PASSFILE)

Get or set the password file.

prefix()
prefix(PREFIX)

Get or set the prompt prefix. Default is no prefix.

timeout()
timeout(TIMEOUT)

Get or set the prompt timeout (in seconds). Default is 10.

DIAGNOSTICS

Unable to use password file %s: %s

The password file doesn't exist or invalid permissions. Make sure the password file has no 'group' or 'other' permissions and is formatted correctly.

CONFIGURATION AND ENVIRONMENT

Authen::Prepare requires no configuration files or environment variables.

An optional password file may be used to store authentication credentials. Environment variables from calling scripts may be used to specify one or more of the named arguments to the constructor (e.g. $ENV{MY_HOSTNAME} or $ENV{MY_PASSFILE}).

DEPENDENCIES

IO::Prompt
Readonly
Text::Glob

INCOMPATIBILITIES

None reported.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to bug-authen-prepare@rt.cpan.org, or through the web interface at http://rt.cpan.org.

AUTHOR

David Narayan <dnarayan@cpan.org>

LICENCE AND COPYRIGHT

Copyright (c) 2007, David Narayan <dnarayan@cpan.org>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.