| 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 | -  |  |  |