Line | |
---|
1 | #!/bin/env perl |
---|
2 | |
---|
3 | # $Id$ |
---|
4 | |
---|
5 | use strict; |
---|
6 | use warnings; |
---|
7 | use Link::Accounts::Remote; |
---|
8 | use Getopt::Long; |
---|
9 | use Term::ReadKey; |
---|
10 | use Pod::Usage; |
---|
11 | |
---|
12 | =head1 NAME |
---|
13 | |
---|
14 | la-chpasswd - Change user password |
---|
15 | |
---|
16 | =head1 SYNOPSIS |
---|
17 | |
---|
18 | la-chpasswd [-u username] |
---|
19 | |
---|
20 | =head1 OPTIONS |
---|
21 | |
---|
22 | =over4 |
---|
23 | |
---|
24 | =item -u username |
---|
25 | |
---|
26 | Specify the username for which the password must be changed. C<$USER> |
---|
27 | envirronment variable is used if not given. |
---|
28 | |
---|
29 | =item --url url |
---|
30 | |
---|
31 | Specify the server url to contact. By default the url is fetched from DNS |
---|
32 | C<_link_accounts> C<TXT> record. |
---|
33 | |
---|
34 | =back |
---|
35 | |
---|
36 | =cut |
---|
37 | |
---|
38 | GetOptions( |
---|
39 | 'url=s' => \my $url, |
---|
40 | 'u|user=s' => \my $user, |
---|
41 | ) or pod2usage(); |
---|
42 | |
---|
43 | $user ||= $ENV{USER}; |
---|
44 | |
---|
45 | ReadMode('noecho'); |
---|
46 | print "Enter current password: "; |
---|
47 | my $oldpassword = ReadLine(0); |
---|
48 | print "\n"; |
---|
49 | |
---|
50 | print "Enter new password: "; |
---|
51 | my $password = ReadLine(0); |
---|
52 | print "\n"; |
---|
53 | print "Confirm new password: "; |
---|
54 | my $password2 = ReadLine(0); |
---|
55 | ReadMode 0; |
---|
56 | print "\n"; |
---|
57 | chomp($password); |
---|
58 | chomp($password2); |
---|
59 | chomp($oldpassword); |
---|
60 | |
---|
61 | if ($password ne $password2) { |
---|
62 | die "Password mismatch\n"; |
---|
63 | } |
---|
64 | |
---|
65 | my $lar = Link::Accounts::Remote->new($url); |
---|
66 | |
---|
67 | if ($lar->query( |
---|
68 | 'user.change_password', |
---|
69 | $user, |
---|
70 | $oldpassword, |
---|
71 | $password, |
---|
72 | )) { |
---|
73 | print "Password succefully changed\n"; |
---|
74 | exit 0; |
---|
75 | } else { |
---|
76 | die "Error when trying to change password: " . $Link::Accounts::Remote::ERROR . "\n"; |
---|
77 | } |
---|
78 | |
---|
Note: See
TracBrowser
for help on using the repository browser.