|
|
|
|
@ -2,6 +2,9 @@ package Lemonldap::NG::Portal::Lib::Password; |
|
|
|
|
|
|
|
|
|
use strict; |
|
|
|
|
use Mouse::Role; |
|
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw( |
|
|
|
|
PE_OK |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
our $VERSION = '2.19.0'; |
|
|
|
|
|
|
|
|
|
@ -12,6 +15,16 @@ has random => ( |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
# Password policy activation rule |
|
|
|
|
has passwordPolicyActivationRule => ( |
|
|
|
|
is => 'ro', |
|
|
|
|
lazy => 1, |
|
|
|
|
default => sub { |
|
|
|
|
$_[0]->p->buildRule( $_[0]->conf->{passwordPolicyActivation} // 0, |
|
|
|
|
'passwordPolicyActivation' ); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
# Generate a complex password based on a regular expression |
|
|
|
|
# @param regexp regular expression |
|
|
|
|
sub gen_password { |
|
|
|
|
@ -19,4 +32,47 @@ sub gen_password { |
|
|
|
|
return $self->random->randregex($regexp); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub newPassword { |
|
|
|
|
my ( $self, $req, $sessionInfo ) = @_; |
|
|
|
|
|
|
|
|
|
# Generate a complex password |
|
|
|
|
my $pwdRegEx; |
|
|
|
|
if ( $self->passwordPolicyActivationRule->( $req, $sessionInfo ) |
|
|
|
|
&& !$self->conf->{randomPasswordRegexp} ) |
|
|
|
|
{ |
|
|
|
|
my $uppers = $self->conf->{passwordPolicyMinUpper} || 3; |
|
|
|
|
my $lowers = $self->conf->{passwordPolicyMinLower} || 5; |
|
|
|
|
my $digits = $self->conf->{passwordPolicyMinDigit} || 2; |
|
|
|
|
my $chars = |
|
|
|
|
$self->conf->{passwordPolicyMinSize} - |
|
|
|
|
$self->conf->{passwordPolicyMinUpper} - |
|
|
|
|
$self->conf->{passwordPolicyMinLower} - |
|
|
|
|
$self->conf->{passwordPolicyMinDigit}; |
|
|
|
|
$chars = 1 if $chars < 1; |
|
|
|
|
$pwdRegEx = "[A-Z]{$uppers}[a-z]{$lowers}\\d{$digits}"; |
|
|
|
|
$pwdRegEx .= |
|
|
|
|
$self->conf->{passwordPolicySpecialChar} eq '__ALL__' |
|
|
|
|
? '\W{$chars}' |
|
|
|
|
: "[$self->{conf}->{passwordPolicySpecialChar}]{$chars}"; |
|
|
|
|
$self->logger->debug("Generated password RegEx: $pwdRegEx"); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
$pwdRegEx = |
|
|
|
|
$self->conf->{randomPasswordRegexp} || '[A-Z]{3}[a-z]{5}.\d{2}'; |
|
|
|
|
$self->logger->debug("Used password RegEx: $pwdRegEx"); |
|
|
|
|
} |
|
|
|
|
return $self->gen_password($pwdRegEx); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sub checkPasswordQuality { |
|
|
|
|
my ( $self, $req, $pwd ) = @_; |
|
|
|
|
require Lemonldap::NG::Portal::Plugins::BasePasswordPolicy; |
|
|
|
|
return PE_OK |
|
|
|
|
unless $self->passwordPolicyActivationRule->( $req, $req->sessionInfo ); |
|
|
|
|
return |
|
|
|
|
$self |
|
|
|
|
->Lemonldap::NG::Portal::Plugins::BasePasswordPolicy::checkBasicPolicy( |
|
|
|
|
$pwd); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
1; |
|
|
|
|
|