Fix aap-passwd argument checking
[apache2-authen-passphrase.git] / aap-passwd
CommitLineData
8443f44e
MG
1#!/usr/bin/perl -T
2use 5.014000;
7c87e995 3use strict;
8443f44e
MG
4use warnings;
5
6our $VERSION = 0.002001;
7c87e995
MG
7
8use Apache2::Authen::Passphrase qw/pwset USER_REGEX/;
9
10use IO::Prompter [qw/-e* -stdio/];
11
7838eb58
MG
12die "Usage: aap-passwd [rootdir] username\n" if @ARGV == 0 || @ARGV > 2;
13($Apache2::Authen::Passphrase::rootdir) = (shift =~ /(.*)/s) if @ARGV == 2;
7c87e995
MG
14
15my $username = shift;
8443f44e
MG
16die "Invalid username\n" unless $username =~ USER_REGEX;
17($username) = ($username =~ /(.*)/s);
7c87e995
MG
18
19my $passwd = prompt 'Enter new Apache2::Authen::Passphrase password: ';
20my $confirm = prompt 'Retype new Apache2::Authen::Passphrase password: ';
21
22die "Sorry, passwords do not match\n" unless $passwd eq $confirm;
23pwset $username, $passwd;
8443f44e 24say 'Password updated successfully'; ## no critic (RequireCheckedSyscalls)
7c87e995
MG
25
26__END__
27
28=head1 NAME
29
30aap-passwd - passwd utility for Apache2::Authen::Passphrase
31
32=head1 SYNOPSIS
33
34 user@hostname:~$ aap-passwd /path/to/rootdir marius
35 Enter new Apache2::Authen::Passphrase password: ***
36 Retype new Apache2::Authen::Passphrase password: ***
37 Password updated successfully
38
39=head1 DESCRIPTION
40
41aap-passwd updates the password of an Apache2::Authen::Passphrase user.
42
43It is used like this:
44
45 aap-passwd /path/to/rootdir username
46
47where the C<rootdir> is the first argument and the username whose password is to be changed is the second argument, or like this:
48
49 aap-passwd username
50
51where the C<rootdir> is taken from the environment and the username is the only argument.
52
53=head1 ENVIRONMENT
54
55=over
56
57=item AAP_ROOTDIR
58
59The default Apache2::Authen::Passphrase C<rootdir>, used if the C<rootdir> is not explicitly given.
60
61=back
62
63=head1 AUTHOR
64
65Marius Gavrilescu C<< <marius@ieval.ro> >>
66
67=head1 COPYRIGHT AND LICENSE
68
69Copyright 2013 Marius Gavrilescu
70
71This file is part of fonbotd.
72
73fonbotd is free software: you can redistribute it and/or modify
74it under the terms of the GNU Affero General Public License as published by
75the Free Software Foundation, either version 3 of the License, or
76(at your option) any later version.
77
78fonbotd is distributed in the hope that it will be useful,
79but WITHOUT ANY WARRANTY; without even the implied warranty of
80MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
81GNU Affero General Public License for more details.
82
83You should have received a copy of the GNU Affero General Public License
84along with fonbotd. If not, see <http://www.gnu.org/licenses/>
85
86
87=cut
This page took 0.012914 seconds and 4 git commands to generate.