Add (optional) scrypt support
[plack-middleware-auth-complex.git] / authcomplex-passwd
CommitLineData
cc5b1b68
MG
1#!/usr/bin/perl
2use 5.014000;
3use strict;
4use warnings;
5
6use IO::Prompter;
7use Plack::Middleware::Auth::Complex;
8
9if (@ARGV < 1) {
10 say STDERR "$0 USERNAME [DSN [DB_USER [DB_PASSWD]]]";
11 exit 1;
12}
13
14my ($username, $dsn, $dbuser, $dbpasswd) = @ARGV;
15$dsn //= $ENV{AUTHCOMPLEX_DSN};
16$dbuser //= $ENV{AUTHCOMPLEX_DBUSER};
17$dbpasswd //= $ENV{AUTHCOMPLEX_DBPASSWD};
18
19$dsn //= 'dbi:Pg:';
20$dbuser //= '';
21$dbpasswd //= '';
22
23my $password = prompt 'Password: ', -echo => '*', -in => *STDIN;
24my $confirm = prompt 'Confirm password: ', -echo => '*', -in => *STDIN;
25
26if ($password ne $confirm) {
27 say STDERR 'The passwords do not match';
28 exit 1;
29}
30
31my $ac = Plack::Middleware::Auth::Complex->new({
32 dbi_connect => [$dsn, $dbuser, $dbpasswd]
33});
34
35$ac->init;
36$ac->set_passphrase($username, $password) or die "$@\n";
37say 'Password changed successfully';
38
391;
40__END__
41
42=encoding utf-8
43
44=head1 NAME
45
46authcomplex-passwd - change user password
47
48=head1 SYNOPSIS
49
50 authcomplex-passwd USERNAME [DSN [DB_USER [DB_PASSWD]]]
51
52 # For example:
53 authcomplex-passwd myuser # dsn defaults to 'dbi:Pg:'
54 authcomplex-passwd myuser 'dbi:Pg:dbname=www-data'
55 authcomplex-passwd myuser 'dbi:Pg:dbname=www-data' db_superuser password123
56
57=head1 DESCRIPTION
58
58b36d0a
MG
59B<NOTE: This script does not support scrypt passphrases.>
60
cc5b1b68
MG
61The authcomplex-passwd script changes the password for an user.
62Takes one mandatory argument, the user whose password should be changed.
63
64The DBI Data Source Name is the second argument to the script, or the
65value of the AUTHCOMPLEX_DSN environment variable if set, or
66C<dbi:Pg:> otherwise.
67
68The username for the database is the third argument to the script, or
69the value of the AUTHCOMPLEX_DBUSER environment variable if set, or an
70empty string otherwise.
71
72The password for the database is the fourth argument to the script, or
73the value of the AUTHCOMPLEX_DBPASSWD environment variable if set, or
74an empty string otherwise.
75
76=head1 AUTHOR
77
78Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
79
80=head1 COPYRIGHT AND LICENSE
81
82Copyright (C) 2015-2017 by Marius Gavrilescu
83
84This library is free software; you can redistribute it and/or modify
85it under the same terms as Perl itself, either Perl version 5.20.1 or,
86at your option, any later version of Perl 5 you may have available.
87
88
89=cut
This page took 0.01293 seconds and 4 git commands to generate.