source: trunk/Link-Accounts-Remote/bin/la-chpasswd @ 1867

Last change on this file since 1867 was 871, checked in by nanardon, 13 years ago
  • fix error detection
  • Property svn:keywords set to Id
File size: 1.3 KB
Line 
1#!/bin/env perl
2
3# $Id$
4
5use strict;
6use warnings;
7use Link::Accounts::Remote;
8use Getopt::Long;
9use Term::ReadKey;
10use 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
26Specify the username for which the password must be changed. C<$USER>
27envirronment variable is used if not given.
28
29=item --url url
30
31Specify the server url to contact. By default the url is fetched from DNS
32C<_link_accounts> C<TXT> record.
33
34=back
35
36=cut
37
38GetOptions(
39    'url=s'      => \my $url,
40    'u|user=s'   => \my $user,
41) or pod2usage();
42
43$user ||= $ENV{USER};
44
45ReadMode('noecho');
46print "Enter current password: ";
47my $oldpassword = ReadLine(0);
48print "\n";
49
50print "Enter new password: ";
51my $password = ReadLine(0);
52print "\n";
53print "Confirm new password: ";
54my $password2 = ReadLine(0);
55ReadMode 0;
56print "\n";
57chomp($password);
58chomp($password2);
59chomp($oldpassword);
60
61if ($password ne $password2) {
62    die "Password mismatch\n";
63}
64
65my $lar = Link::Accounts::Remote->new($url);
66
67if ($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.