source: LATMOS-Accounts/bin/la-passwd @ 656

Last change on this file since 656 was 656, checked in by nanardon, 14 years ago
  • error messages goes to STDERR
  • Property svn:executable set to *
File size: 1.4 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use Pod::Usage;
8use Term::ReadKey;
9
10=head1 NAME
11
12    la-passwd - set user password
13
14=head1 SYNOPSIS
15
16    la-passwd [options] userid
17
18=head1 OPTIONS
19
20=over 4
21
22=item -c|--config configfile
23
24Use this configuration file instead of the default one.
25
26=item -b|--base basename
27
28Query this specific base instead of the default one.
29
30=item -t|--test
31
32Don't change the password but check its validity using CrackLib.
33
34=back
35
36=cut
37
38GetOptions(
39    'c|config=s' => \my $config,
40    'b|base=s'   => \my $base,
41    't|test'     => \my $test,
42    'help'       => sub { pod2usage(0) },
43) or pod2usage();
44
45if (!$ARGV[0]) {warn "You must specify 'userid', aborting\n"; pod2usage(); }
46
47my $otype = 'user';
48
49my $LA = LATMOS::Accounts->new($config, noacl => 1);
50my $labase = $base ? $LA->base($base) : $LA->default_base;
51$labase && $labase->load or die "Cannot load base";
52
53my $obj = $labase->get_object($otype, $ARGV[0]) or do {
54    die "Object $otype $ARGV[0] not found\n";
55};
56
57ReadMode('noecho');
58print "Enter password: ";
59my $password = ReadLine(0);
60ReadMode 0;
61print "\n";
62
63print $obj->check_password($password) . "\n";
64
65exit(0)  if($test);
66
67if ($obj->set_password($password)) {
68    print "Password succefully changed\n";
69    $labase->commit;
70    exit 0;
71} else {
72    warn "Error when trying to change password\n";
73    exit 1;
74}
Note: See TracBrowser for help on using the repository browser.