- Timestamp:
- 10/02/19 09:56:44 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Object.pm
r2285 r2287 9 9 use LATMOS::Accounts::Utils; 10 10 use Term::ReadLine; 11 use Term::ReadKey; 11 12 use Text::ParseWords; 12 13 use Getopt::Long; … … 538 539 $self->add_func('banpasswd', { 539 540 code => sub { 540 my ( $env , $ban) = @_;541 my ( $env ) = @_; 541 542 foreach my $obj (@{$env->{_objects}}) { 542 543 $obj->banCurrentPassword; … … 545 546 }, 546 547 completion => sub {}, 548 }); 549 550 =head3 passwd 551 552 Set password to selected user. If multiple users are selected the same password will be set to all users 553 554 Options: 555 556 =over 4 557 558 =item -f|--force Ignore password quality check 559 560 =item -r|--random Generate a random password for each users 561 562 =item -o|--output Write login:password into a file (usefull with --random) 563 564 =back 565 566 =cut 567 568 $self->add_func('passwd', { 569 code => sub { 570 my $env = shift; 571 my %gen_options = (); 572 my ( $password ) = $self->getoption( 573 { 574 'f|force' => \my $force, 575 'r|random' => \my $random, 576 'p' => \$gen_options{nonalpha}, 577 'syl' => \$gen_options{syllables}, 578 'l=i' => \$gen_options{length}, 579 'o=s' => \my $output, 580 581 }, @_ 582 ); 583 584 if (!($password || $random)) { 585 ReadMode('noecho'); 586 print "Enter password: "; 587 $password = ReadLine(0); 588 ReadMode 0; 589 print "\n"; 590 chomp($password); 591 } 592 593 $password ||= ''; 594 my %resPasswd = (); 595 596 my $sbase = $self->La->sync_access(); 597 598 foreach my $obj (@{$env->{_objects}}) { 599 my $sobj = $sbase->get_object($obj->type, $obj->id); 600 if ($random) { 601 $password = LATMOS::Accounts::Utils::genpassword( 602 %gen_options 603 ); 604 } 605 606 my $res = $sobj->check_password($password); 607 if ($res ne 'ok') { 608 warn "Password quality: $res\n"; 609 if (!$force) { 610 warn "Cannot set bad password, use --force to bypass security\n"; 611 return; 612 } 613 } 614 if ($sobj->set_password($password)) { 615 $resPasswd{$obj->id} = $password; 616 print "Password succefully changed\n"; 617 $env->commit; 618 return 1; 619 } else { 620 warn "Error when trying to change password\n"; 621 return 0; 622 } 623 } 624 625 if ($output) { 626 open(my $handle, '>', $output) or do { 627 warn "Cannot open $output: $!"; 628 return; 629 }; 630 foreach (sort keys %resPasswd) { 631 print $handle $_ . ':' . $resPasswd{$_} . "\n"; 632 } 633 close($handle); 634 } 635 }, 636 completion => sub { 637 return (qw(-f --force -r --random -p --syl -l -o)); 638 }, 547 639 }); 548 640
Note: See TracChangeset
for help on using the changeset viewer.