From cc5b1b68917bbed12efef810f71ad386f8afed5e Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sat, 25 Mar 2017 21:10:23 +0200 Subject: [PATCH] Add authcomplex-passwd script --- MANIFEST | 1 + Makefile.PL | 2 + README | 1 + authcomplex-passwd | 87 ++++++++++++++++++++++++++++ lib/Plack/Middleware/Auth/Complex.pm | 2 +- 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100755 authcomplex-passwd diff --git a/MANIFEST b/MANIFEST index 16169f9..f5e6ac1 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,3 +1,4 @@ +authcomplex-passwd Changes Makefile.PL MANIFEST diff --git a/Makefile.PL b/Makefile.PL index 21ef80a..531b607 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -7,6 +7,7 @@ WriteMakefile( ABSTRACT_FROM => 'lib/Plack/Middleware/Auth/Complex.pm', AUTHOR => 'Marius Gavrilescu ', 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 e3956a6..9473b92 100644 --- 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 index 0000000..febbe05 --- /dev/null +++ b/authcomplex-passwd @@ -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 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, Emarius@ieval.roE + +=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 diff --git a/lib/Plack/Middleware/Auth/Complex.pm b/lib/Plack/Middleware/Auth/Complex.pm index bc6a33b..6c08273 100644 --- a/lib/Plack/Middleware/Auth/Complex.pm +++ b/lib/Plack/Middleware/Auth/Complex.pm @@ -519,7 +519,7 @@ Marius Gavrilescu, Emarius@ieval.roE =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, -- 2.39.2