* Fri Feb 21 2025 Jean-Philippe Pialasse <jpp@koozali.org> 11.0.0-57.sme

- upgrade validate_password sub to use esmith::util [SME: 12937]
  and deduplicate code
This commit is contained in:
2025-02-21 01:35:33 -05:00
parent 887af04bfe
commit c2427189d5
5 changed files with 25 additions and 79 deletions

View File

@@ -13,7 +13,7 @@ use warnings;
use Mojo::Base 'Mojolicious::Controller';
use Locale::gettext;
use SrvMngr::I18N;
use SrvMngr qw( theme_list init_session is_normal_password );
use SrvMngr qw( theme_list init_session validate_password );
use esmith::AccountsDB;
use esmith::ConfigDB;
use esmith::DomainsDB;
@@ -385,31 +385,6 @@ sub check_password {
return validate_password($c, $strength, $password);
} ## end sub check_password
sub validate_password {
my ($c, $strength, $pass) = @_;
use Crypt::Cracklib;
my $reason;
if ($strength eq "none") {
return $c->l("Passwords must be at least 7 characters long") unless (length($pass) > 6);
return "OK";
}
$reason = is_normal_password($c, $pass, undef);
return $reason unless ($reason eq "OK");
return "OK" unless ($strength eq "strong");
if (-f '/usr/lib64/cracklib_dict.pwd') {
$reason = fascist_check($pass, '/usr/lib64/cracklib_dict');
} else {
$reason = fascist_check($pass, '/usr/lib/cracklib_dict');
}
$reason ||= "Software error: password check failed";
return "OK" if ($reason eq "ok");
return
$c->l("Bad Password Choice") . ": "
. $c->l("The password you have chosen is not a good choice, because") . " "
. $c->($reason) . ".";
} ## end sub validate_password
=head2 group_list()