View | Details | Raw Unified | Return to bug 17746
Collapse All | Expand All

(-)a/debian/scripts/koha-reset-passwd (-3 / +1 lines)
Lines 44-50 set_password() Link Here
44
{
44
{
45
    local instancename=$1
45
    local instancename=$1
46
    local userid=$2
46
    local userid=$2
47
    local password=$(pwgen 12 1)
48
47
49
    # Optionally use alternative paths for a dev install
48
    # Optionally use alternative paths for a dev install
50
    adjust_paths_dev_install $1
49
    adjust_paths_dev_install $1
Lines 58-66 set_password() Link Here
58
    if sudo -u "$instancename-koha" -H \
57
    if sudo -u "$instancename-koha" -H \
59
        env PERL5LIB=$PERL5LIB \
58
        env PERL5LIB=$PERL5LIB \
60
        KOHA_CONF="/etc/koha/sites/$instancename/koha-conf.xml" \
59
        KOHA_CONF="/etc/koha/sites/$instancename/koha-conf.xml" \
61
        $KOHA_BINDIR/admin/set_password.pl --userid $userid --password $password ; then
60
        $KOHA_BINDIR/admin/set_password.pl --userid $userid ; then
62
61
63
        echo "$userid $password"
64
        return 0
62
        return 0
65
    else
63
    else
66
        return 1
64
        return 1
(-)a/misc/admin/set_password.pl (-4 / +19 lines)
Lines 18-25 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
22
use Bytes::Random::Secure;
21
use Getopt::Long;
23
use Getopt::Long;
22
use Pod::Usage;
24
use Pod::Usage;
25
use String::Random;
23
26
24
use Koha::Patrons;
27
use Koha::Patrons;
25
28
Lines 33-39 GetOptions( Link Here
33
);
36
);
34
37
35
pod2usage(1) if $help;
38
pod2usage(1) if $help;
36
pod2usage("password is mandatory")     unless $password;
37
39
38
unless ( $userid or $patron_id or $cardnumber ) {
40
unless ( $userid or $patron_id or $cardnumber ) {
39
    pod2usage("userid is mandatory")       unless $userid;
41
    pod2usage("userid is mandatory")       unless $userid;
Lines 41-46 unless ( $userid or $patron_id or $cardnumber ) { Link Here
41
    pod2usage("cardnumber is mandatory")   unless $cardnumber;
43
    pod2usage("cardnumber is mandatory")   unless $cardnumber;
42
}
44
}
43
45
46
unless ($password) {
47
    my $generator  = String::Random->new( rand_gen => \&alt_rand );
48
    $password      = $generator->randregex('[A-Za-z][A-Za-z0-9_]{6}.[A-Za-z][A-Za-z0-9_]{6}\d');
49
}
50
44
my $filter;
51
my $filter;
45
52
46
if ( $userid ) {
53
if ( $userid ) {
Lines 64-69 unless ( $patrons->count > 0 ) { Link Here
64
my $patron = $patrons->next;
71
my $patron = $patrons->next;
65
$patron->set_password({ password => $password, skip_validation => 1 });
72
$patron->set_password({ password => $password, skip_validation => 1 });
66
73
74
print $patron->userid . " " . $password . "\n";
75
76
sub alt_rand { # Alternative randomizer
77
    my ($max) = @_;
78
    my $random = Bytes::Random::Secure->new( NonBlocking => 1 );
79
    my $r = $random->irand / 2**32;
80
    return int( $r * $max );
81
}
82
67
=head1 NAME
83
=head1 NAME
68
84
69
set_password.pl - Set the specified password for the user in Koha
85
set_password.pl - Set the specified password for the user in Koha
Lines 75-81 set_password.pl Link Here
75
91
76
 Options:
92
 Options:
77
   -?|--help        brief help message
93
   -?|--help        brief help message
78
   --password       the password to be set
94
   --password       the password to be set (optional)
79
   --userid         the userid to be used to find the patron
95
   --userid         the userid to be used to find the patron
80
   --patron_id      the borrowernumber for the patron
96
   --patron_id      the borrowernumber for the patron
81
   --cardnumber     the cardnumber for the patron
97
   --cardnumber     the cardnumber for the patron
Lines 94-100 The patron's userid (for finding the patron) Link Here
94
110
95
=item B<--password>
111
=item B<--password>
96
112
97
The password to be set in the database
113
The password to be set in the database. If no password is passed, a random one is generated.
98
114
99
=item B<--patron_id>
115
=item B<--patron_id>
100
116
101
- 

Return to bug 17746