@@ -, +, @@ password if required - Follow the steps from the original platch - Verify all behaves as expected --- debian/scripts/koha-reset-passwd | 4 +--- misc/admin/set_password.pl | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) --- a/debian/scripts/koha-reset-passwd +++ a/debian/scripts/koha-reset-passwd @@ -44,7 +44,6 @@ set_password() { local instancename=$1 local userid=$2 - local password=$(pwgen 12 1) # Optionally use alternative paths for a dev install adjust_paths_dev_install $1 @@ -58,9 +57,8 @@ set_password() if sudo -u "$instancename-koha" -H \ env PERL5LIB=$PERL5LIB \ KOHA_CONF="/etc/koha/sites/$instancename/koha-conf.xml" \ - $KOHA_BINDIR/admin/set_password.pl --userid $userid --password $password ; then + $KOHA_BINDIR/admin/set_password.pl --userid $userid ; then - echo "$userid $password" return 0 else return 1 --- a/misc/admin/set_password.pl +++ a/misc/admin/set_password.pl @@ -18,8 +18,11 @@ # along with Koha; if not, see . use Modern::Perl; + +use Bytes::Random::Secure; use Getopt::Long; use Pod::Usage; +use String::Random; use Koha::Patrons; @@ -33,7 +36,6 @@ GetOptions( ); pod2usage(1) if $help; -pod2usage("password is mandatory") unless $password; unless ( $userid or $patron_id or $cardnumber ) { pod2usage("userid is mandatory") unless $userid; @@ -41,6 +43,11 @@ unless ( $userid or $patron_id or $cardnumber ) { pod2usage("cardnumber is mandatory") unless $cardnumber; } +unless ($password) { + my $generator = String::Random->new( rand_gen => \&alt_rand ); + $password = $generator->randregex('[A-Za-z][A-Za-z0-9_]{6}.[A-Za-z][A-Za-z0-9_]{6}\d'); +} + my $filter; if ( $userid ) { @@ -64,6 +71,15 @@ unless ( $patrons->count > 0 ) { my $patron = $patrons->next; $patron->set_password({ password => $password, skip_validation => 1 }); +print $patron->userid . " " . $password . "\n"; + +sub alt_rand { # Alternative randomizer + my ($max) = @_; + my $random = Bytes::Random::Secure->new( NonBlocking => 1 ); + my $r = $random->irand / 2**32; + return int( $r * $max ); +} + =head1 NAME set_password.pl - Set the specified password for the user in Koha @@ -75,7 +91,7 @@ set_password.pl Options: -?|--help brief help message - --password the password to be set + --password the password to be set (optional) --userid the userid to be used to find the patron --patron_id the borrowernumber for the patron --cardnumber the cardnumber for the patron @@ -94,7 +110,7 @@ The patron's userid (for finding the patron) =item B<--password> -The password to be set in the database +The password to be set in the database. If no password is passed, a random one is generated. =item B<--patron_id> --