Add authcomplex-passwd script
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 25 Mar 2017 19:10:23 +0000 (21:10 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 25 Mar 2017 19:12:17 +0000 (21:12 +0200)
MANIFEST
Makefile.PL
README
authcomplex-passwd [new file with mode: 0755]
lib/Plack/Middleware/Auth/Complex.pm

index 16169f9c8b150e117ec63501382d10d75a228e02..f5e6ac1c867742fdff48637f20af5e9093e70857 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,3 +1,4 @@
+authcomplex-passwd
 Changes
 Makefile.PL
 MANIFEST
index 21ef80a7fd3049791ca56a2aa853a5e94ec32b2e..531b6075be43d2406e45b1c092cf6bf27c9a16c4 100644 (file)
@@ -7,6 +7,7 @@ WriteMakefile(
        ABSTRACT_FROM     => 'lib/Plack/Middleware/Auth/Complex.pm',
        AUTHOR            => 'Marius Gavrilescu <marius@ieval.ro>',
        MIN_PERL_VERSION  => '5.14.0',
+       EXE_FILES         => ['authcomplex-passwd'],
        LICENSE           => 'perl',
        SIGN              => 1,
        BUILD_REQUIRES    => {
@@ -21,6 +22,7 @@ WriteMakefile(
                   DBI                               0
                   Email::Simple                     0
                   Email::Sender::Simple             0
+                  IO::Prompter                      0
                   Plack::Request                    0
                   Tie::Hash::Expire                 0/,
        },
diff --git a/README b/README
index e3956a6f0e06a31b2e1721638c477b35a1a7627c..9473b9275e1ca4be1ffc9b56bf6b91f580dbcff9 100644 (file)
--- a/README
+++ b/README
@@ -25,6 +25,7 @@ This module requires these other modules and libraries:
 * Bytes::Random::Secure
 * DBI + DBD::SQLite
 * Email::Simple
+* IO::Prompter
 * Plack
 * Tie::Hash::Expire
 
diff --git a/authcomplex-passwd b/authcomplex-passwd
new file mode 100755 (executable)
index 0000000..febbe05
--- /dev/null
@@ -0,0 +1,87 @@
+#!/usr/bin/perl
+use 5.014000;
+use strict;
+use warnings;
+
+use IO::Prompter;
+use Plack::Middleware::Auth::Complex;
+
+if (@ARGV < 1) {
+       say STDERR "$0 USERNAME [DSN [DB_USER [DB_PASSWD]]]";
+       exit 1;
+}
+
+my ($username, $dsn, $dbuser, $dbpasswd) = @ARGV;
+$dsn //= $ENV{AUTHCOMPLEX_DSN};
+$dbuser //= $ENV{AUTHCOMPLEX_DBUSER};
+$dbpasswd //= $ENV{AUTHCOMPLEX_DBPASSWD};
+
+$dsn //= 'dbi:Pg:';
+$dbuser //= '';
+$dbpasswd //= '';
+
+my $password = prompt 'Password: ', -echo => '*', -in => *STDIN;
+my $confirm  = prompt 'Confirm password: ', -echo => '*', -in => *STDIN;
+
+if ($password ne $confirm) {
+       say STDERR 'The passwords do not match';
+       exit 1;
+}
+
+my $ac = Plack::Middleware::Auth::Complex->new({
+       dbi_connect => [$dsn, $dbuser, $dbpasswd]
+});
+
+$ac->init;
+$ac->set_passphrase($username, $password) or die "$@\n";
+say 'Password changed successfully';
+
+1;
+__END__
+
+=encoding utf-8
+
+=head1 NAME
+
+authcomplex-passwd - change user password
+
+=head1 SYNOPSIS
+
+  authcomplex-passwd USERNAME [DSN [DB_USER [DB_PASSWD]]]
+
+  # For example:
+  authcomplex-passwd myuser # dsn defaults to 'dbi:Pg:'
+  authcomplex-passwd myuser 'dbi:Pg:dbname=www-data'
+  authcomplex-passwd myuser 'dbi:Pg:dbname=www-data' db_superuser password123
+
+=head1 DESCRIPTION
+
+The authcomplex-passwd script changes the password for an user.
+Takes one mandatory argument, the user whose password should be changed.
+
+The DBI Data Source Name is the second argument to the script, or the
+value of the AUTHCOMPLEX_DSN environment variable if set, or
+C<dbi:Pg:> otherwise.
+
+The username for the database is the third argument to the script, or
+the value of the AUTHCOMPLEX_DBUSER environment variable if set, or an
+empty string otherwise.
+
+The password for the database is the fourth argument to the script, or
+the value of the AUTHCOMPLEX_DBPASSWD environment variable if set, or
+an empty string otherwise.
+
+=head1 AUTHOR
+
+Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2015-2017 by Marius Gavrilescu
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself, either Perl version 5.20.1 or,
+at your option, any later version of Perl 5 you may have available.
+
+
+=cut
index bc6a33b408f8bec8d37d1c6cb7726ff3577a7949..6c08273df4b1ad9f11d021cd6ad165cc4f95342f 100644 (file)
@@ -519,7 +519,7 @@ Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright (C) 2015 by Marius Gavrilescu
+Copyright (C) 2015-2017 by Marius Gavrilescu
 
 This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself, either Perl version 5.20.1 or,
This page took 0.014504 seconds and 4 git commands to generate.