Passwd-Keyring-Auto
view release on metacpan or search on metacpan
lib/Passwd/Keyring/Auto.pm view on Meta::CPAN
package Passwd::Keyring::Auto;
use warnings;
use strict;
use base 'Exporter';
our @EXPORT = qw(get_keyring);
use Carp;
use Passwd::Keyring::Auto::Chooser;
=head1 NAME
Passwd::Keyring::Auto - interface to secure password storage(s)
=head1 VERSION
Version 1.0000
=cut
our $VERSION = '1.0000';
=head1 SYNOPSIS
Passwd::Keyring is about securely preserving passwords and other
sensitive data (for example API keys, OAuth tokens etc) in backends
like Gnome Keyring, KDE Wallet, OSX/Keychain etc.
While modules like Passwd::Keyring::Gnome handle specific backends,
Passwd::Keyring::Auto tries to pick the best backend available,
considering the current desktop environment, program options, and user
configuration.
use Passwd::Keyring::Auto; # get_keyring
my $keyring = get_keyring(app=>"My super scraper", group=>"Social passwords");
my $username = "someuser";
my $password = $keyring->get_password($username, "mylostspace.com");
unless($password) {
# ... somehow interactively prompt for password
$keyring->set_password($username, $password, "mylostspace.com");
}
login_somewhere_using($username, $password);
if( password_was_wrong ) {
$keyring->clear_password($username, "mylostspace.com");
}
If any secure backend is available, password is preserved
for successive runs, and user need not be prompted again.
The choice can be impacted by configuration file, some environment
variables and/or additional parameters, see L</BACKEND SELECTION CRITERIA>.
One can skip this module and be explicit if he or she knows which
keyring is to be used:
use Passwd::Keyring::Gnome;
my $keyring = Passwd::Keyring::Gnome->new();
# ... from there as above
=head1 SUBROUTINES/METHODS
=head2 get_keyring
my $ring = get_keyring()
my $ring = get_keyring(app=>'MyApp', group=>'SyncPasswords');
my $ring = get_keyring(app=>'MyApp', group=>'Uploads',
config=>"$ENV{HOME}/.passwd-keyring-business.cfg");
my $ring = get_keyring(app=>'MyApp', group=>'Scrappers',
prefer=>['Gnome', 'PWSafe3'],
forbid=>['KDEWallet']);
my $ring = get_keyring(app=>'MyApp', group=>'Scrappers',
force=>['KDEWallet']);
my $ring = get_keyring(app=>'MyApp', group=>'SyncPasswords',
%backend_specific_options);
Returns the keyring object most appropriate for the current system
(and matching specified criteria, and applying user configuration) and
initiates it.
The function inspects context the application runs in (operating
system, presence of GUI sessions etc), decides which backends seem
suitable and in what order of preference, then tries all suitable
backends and returns first succesfully loaded and initialized (or
croaks if there is none). See L</BACKEND SELECTION CRITERIA> for
( run in 2.127 seconds using v1.01-cache-2.11-cpan-5c0b1e786e0 )