« blib/lib/Lemonldap/NG/Portal/Lib/OpenID/Server.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Issuer/CAS.pm »
| 1 | package Lemonldap::NG::Portal::Plugins::BasePasswordPolicy; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 105 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 105 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 105 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 105 | ▶ | use Lemonldap::NG::Portal::Main::Constants qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | PE_OK | ||||||||||||||||||||||||||||
| 8 | PE_ERROR | ||||||||||||||||||||||||||||
| 9 | PE_PP_PASSWORD_TOO_LONG | ||||||||||||||||||||||||||||
| 10 | PE_PP_PASSWORD_TOO_SHORT | ||||||||||||||||||||||||||||
| 11 | PE_PP_NOT_ALLOWED_CHARACTER | ||||||||||||||||||||||||||||
| 12 | PE_PP_NOT_ALLOWED_CHARACTERS | ||||||||||||||||||||||||||||
| 13 | PE_PP_INSUFFICIENT_PASSWORD_QUALITY | ||||||||||||||||||||||||||||
| 14 | 105 | ); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 105 | our $VERSION = '2.20.0'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 105 | extends 'Lemonldap::NG::Portal::Main::Plugin'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 105 | ▶ | use constant hook => { passwordBeforeChange => 'checkPasswordQuality', }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 105 | has pwdPolicyRule => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 331 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 331 | my ($self) = @_; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | my $pwdPolicyRule = $self->p->buildRule( | ||||||||||||||||||||||||||||
| 27 | $self->conf->{passwordPolicyActivation}, | ||||||||||||||||||||||||||||
| 28 | 331 | "Password policy activation rule" | |||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | 331 | $self->pwdPolicyRule($pwdPolicyRule); | |||||||||||||||||||||||||||
| 31 | 331 | ▶ | return 0 unless $pwdPolicyRule; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | $self->p->addPasswordPolicyDisplay( | ||||||||||||||||||||||||||||
| 34 | 'ppolicy-minsize', | ||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | condition => $self->conf->{passwordPolicyMinSize}, | ||||||||||||||||||||||||||||
| 37 | value => $self->conf->{passwordPolicyMinSize}, | ||||||||||||||||||||||||||||
| 38 | 331 | label => "passwordPolicyMinSize", | |||||||||||||||||||||||||||
| 39 | order => 101, | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | $self->p->addPasswordPolicyDisplay( | ||||||||||||||||||||||||||||
| 43 | 'ppolicy-minlower', | ||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||
| 45 | condition => $self->conf->{passwordPolicyMinLower}, | ||||||||||||||||||||||||||||
| 46 | value => $self->conf->{passwordPolicyMinLower}, | ||||||||||||||||||||||||||||
| 47 | 331 | label => "passwordPolicyMinLower", | |||||||||||||||||||||||||||
| 48 | order => 102, | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||
| 51 | $self->p->addPasswordPolicyDisplay( | ||||||||||||||||||||||||||||
| 52 | 'ppolicy-minupper', | ||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||
| 54 | condition => $self->conf->{passwordPolicyMinUpper}, | ||||||||||||||||||||||||||||
| 55 | value => $self->conf->{passwordPolicyMinUpper}, | ||||||||||||||||||||||||||||
| 56 | 331 | label => "passwordPolicyMinUpper", | |||||||||||||||||||||||||||
| 57 | order => 103, | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||
| 60 | $self->p->addPasswordPolicyDisplay( | ||||||||||||||||||||||||||||
| 61 | 'ppolicy-mindigit', | ||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||
| 63 | condition => $self->conf->{passwordPolicyMinDigit}, | ||||||||||||||||||||||||||||
| 64 | value => $self->conf->{passwordPolicyMinDigit}, | ||||||||||||||||||||||||||||
| 65 | 331 | label => "passwordPolicyMinDigit", | |||||||||||||||||||||||||||
| 66 | order => 104, | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||
| 69 | $self->p->addPasswordPolicyDisplay( | ||||||||||||||||||||||||||||
| 70 | 'ppolicy-minspechar', | ||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||
| 72 | condition => ( | ||||||||||||||||||||||||||||
| 73 | $self->conf->{passwordPolicyMinSpeChar} | ||||||||||||||||||||||||||||
| 74 | && $self->conf->{passwordPolicySpecialChar} | ||||||||||||||||||||||||||||
| 75 | ), | ||||||||||||||||||||||||||||
| 76 | value => $self->conf->{passwordPolicyMinSpeChar}, | ||||||||||||||||||||||||||||
| 77 | 331 | ▶ | label => "passwordPolicyMinSpeChar", | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->conf->{'passwordPolicyMinSpeChar'} && $self->conf->{'passwordPolicySpecialChar'}
MC/DC0%0/2
$self->conf->{'passwordPolicyMinSpeChar'} && $self->conf->{'passwordPolicySpecialChar'}
$self->conf->{'passwordPolicyMinSpeChar'}
$self->conf->{'passwordPolicySpecialChar'}
Truth table33%1/3
A && B
A= $self->conf->{'passwordPolicyMinSpeChar'}B= $self->conf->{'passwordPolicySpecialChar'}
| |||||||||||||||||||||||||||||
| 78 | order => 105, | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||
| 81 | $self->p->addPasswordPolicyDisplay( | ||||||||||||||||||||||||||||
| 82 | 'ppolicy-allowedspechar', | ||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||
| 84 | condition => ( | ||||||||||||||||||||||||||||
| 85 | 331 | ▶ | $self->conf->{passwordPolicyMinSpeChar} && $self->p->speChars() | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->conf->{'passwordPolicyMinSpeChar'} && $self->p->speChars
MC/DC0%0/2
$self->conf->{'passwordPolicyMinSpeChar'} && $self->p->speChars
$self->conf->{'passwordPolicyMinSpeChar'}
$self->p->speChars
Truth table33%1/3
A && B
A= $self->conf->{'passwordPolicyMinSpeChar'}B= $self->p->speChars
| |||||||||||||||||||||||||||||
| 86 | ), | ||||||||||||||||||||||||||||
| 87 | value => $self->p->speChars(), | ||||||||||||||||||||||||||||
| 88 | label => "passwordPolicySpecialChar", | ||||||||||||||||||||||||||||
| 89 | order => 106, | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||
| 92 | $self->p->addPasswordPolicyDisplay( | ||||||||||||||||||||||||||||
| 93 | 'ppolicy-maxsize', | ||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||
| 95 | condition => $self->conf->{passwordPolicyMaxSize}, | ||||||||||||||||||||||||||||
| 96 | value => $self->conf->{passwordPolicyMaxSize}, | ||||||||||||||||||||||||||||
| 97 | 331 | label => "passwordPolicyMaxSize", | |||||||||||||||||||||||||||
| 98 | order => 107, | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 331 | return 1; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 2 | ▶ | sub checkPasswordQuality { | ||||||||||||||||||||||||||
|
Subroutine
checkPasswordQuality: called CC=2 SCAR=7.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 106 | 2 | my ( $self, $req, $user, $password, $old ) = @_; | |||||||||||||||||||||||||||
| 107 | 2 | ▶ | if ( $self->pwdPolicyRule->( $req, $req->userData ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 2 | $self->logger->debug("Checking basic password policy for $user"); | |||||||||||||||||||||||||||
| 109 | 2 | return $self->checkBasicPolicy($password); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||
| 112 | 0 | $self->logger->debug("Skipping basic password policy for $user"); | |||||||||||||||||||||||||||
| 113 | 0 | return PE_OK; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 2 | ▶ | sub checkBasicPolicy { | ||||||||||||||||||||||||||
|
Subroutine
checkBasicPolicy: called CC=23 SCAR=55.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 118 | 2 | my ( $self, $password, $old ) = @_; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | # Min size | ||||||||||||||||||||||||||||
| 121 | 2 | ▶ | if ( $self->conf->{passwordPolicyMinSize} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->conf->{"passwordPolicyMinSize"} and length $password < $self->conf->{"passwordPolicyMinSize"}
MC/DC0%0/2
$self->conf->{"passwordPolicyMinSize"} and length $password < $self->conf->{"passwordPolicyMinSize"}
$self->conf->{"passwordPolicyMinSize"}
length $password < $self->conf->{"passwordPolicyMinSize"}
Truth table33%1/3
A and B
A= $self->conf->{"passwordPolicyMinSize"}B= length $password < $self->conf->{"passwordPolicyMinSize"}
| |||||||||||||||||||||||||||||
| 122 | and length($password) < $self->conf->{passwordPolicyMinSize} ) | ||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||
| 124 | 0 | $self->logger->error("Password too short"); | |||||||||||||||||||||||||||
| 125 | 0 | return PE_PP_PASSWORD_TOO_SHORT; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | # Max size | ||||||||||||||||||||||||||||
| 129 | 2 | ▶ | if ( $self->conf->{passwordPolicyMaxSize} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->conf->{"passwordPolicyMaxSize"} and length $password > $self->conf->{"passwordPolicyMaxSize"}
MC/DC0%0/2
$self->conf->{"passwordPolicyMaxSize"} and length $password > $self->conf->{"passwordPolicyMaxSize"}
$self->conf->{"passwordPolicyMaxSize"}
length $password > $self->conf->{"passwordPolicyMaxSize"}
Truth table33%1/3
A and B
A= $self->conf->{"passwordPolicyMaxSize"}B= length $password > $self->conf->{"passwordPolicyMaxSize"}
| |||||||||||||||||||||||||||||
| 130 | and length($password) > $self->conf->{passwordPolicyMaxSize} ) | ||||||||||||||||||||||||||||
| 131 | { | ||||||||||||||||||||||||||||
| 132 | 0 | $self->logger->error("Password too long"); | |||||||||||||||||||||||||||
| 133 | 0 | return PE_PP_PASSWORD_TOO_LONG; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | # Min lower | ||||||||||||||||||||||||||||
| 137 | 2 | ▶ | if ( $self->conf->{passwordPolicyMinLower} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 0 | my $lower = 0; | |||||||||||||||||||||||||||
| 139 | 0 | ▶ | $lower++ while ( $password =~ m/\p{lowercase}/g ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if ( $lower < $self->conf->{passwordPolicyMinLower} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | $self->logger->error("Password has not enough lower characters"); | |||||||||||||||||||||||||||
| 142 | 0 | return PE_PP_INSUFFICIENT_PASSWORD_QUALITY; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # Min upper | ||||||||||||||||||||||||||||
| 147 | 2 | ▶ | if ( $self->conf->{passwordPolicyMinUpper} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 0 | my $upper = 0; | |||||||||||||||||||||||||||
| 149 | 0 | ▶ | $upper++ while ( $password =~ m/\p{uppercase}/g ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if ( $upper < $self->conf->{passwordPolicyMinUpper} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 0 | $self->logger->error("Password has not enough upper characters"); | |||||||||||||||||||||||||||
| 152 | 0 | return PE_PP_INSUFFICIENT_PASSWORD_QUALITY; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | # Min digit | ||||||||||||||||||||||||||||
| 157 | 2 | ▶ | if ( $self->conf->{passwordPolicyMinDigit} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 0 | my $digit = 0; | |||||||||||||||||||||||||||
| 159 | 0 | ▶ | $digit++ while ( $password =~ m/\d/g ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if ( $digit < $self->conf->{passwordPolicyMinDigit} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | $self->logger->error("Password has not enough digit characters"); | |||||||||||||||||||||||||||
| 162 | 0 | return PE_PP_INSUFFICIENT_PASSWORD_QUALITY; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | ### Special characters policy | ||||||||||||||||||||||||||||
| 167 | 2 | my $speChars = $self->conf->{passwordPolicySpecialChar}; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | ## Min special characters | ||||||||||||||||||||||||||||
| 170 | # Just number of special characters must be checked | ||||||||||||||||||||||||||||
| 171 | 2 | ▶ | if ( $self->conf->{passwordPolicyMinSpeChar} && $speChars eq '__ALL__' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->conf->{"passwordPolicyMinSpeChar"} and $speChars eq "__ALL__"
MC/DC0%0/2
$self->conf->{"passwordPolicyMinSpeChar"} and $speChars eq "__ALL__"
$self->conf->{"passwordPolicyMinSpeChar"}
$speChars eq "__ALL__"
Truth table33%1/3
A and B
A= $self->conf->{"passwordPolicyMinSpeChar"}B= $speChars eq "__ALL__"
| |||||||||||||||||||||||||||||
| 172 | 0 | my $spe = $password =~ s/[\W_]//g; | |||||||||||||||||||||||||||
| 173 | 0 | ▶ | if ( $spe < $self->conf->{passwordPolicyMinSpeChar} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 0 | $self->logger->error("Password has not enough special characters"); | |||||||||||||||||||||||||||
| 175 | 0 | return PE_PP_INSUFFICIENT_PASSWORD_QUALITY; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | 0 | return PE_OK; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | # Check number of special characters | ||||||||||||||||||||||||||||
| 181 | 2 | ▶ | if ( $self->conf->{passwordPolicyMinSpeChar} && $speChars ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->conf->{"passwordPolicyMinSpeChar"} and $speChars
MC/DC0%0/2
$self->conf->{"passwordPolicyMinSpeChar"} and $speChars
$self->conf->{"passwordPolicyMinSpeChar"}
$speChars
Truth table33%1/3
A and B
A= $self->conf->{"passwordPolicyMinSpeChar"}B= $speChars
| |||||||||||||||||||||||||||||
| 182 | 0 | my $test = $password; | |||||||||||||||||||||||||||
| 183 | 0 | my $spe = $test =~ s/[\Q$speChars\E]//g; | |||||||||||||||||||||||||||
| 184 | 0 | ▶ | if ( $spe < $self->conf->{passwordPolicyMinSpeChar} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 0 | $self->logger->error("Password has not enough special characters"); | |||||||||||||||||||||||||||
| 186 | 0 | return PE_PP_INSUFFICIENT_PASSWORD_QUALITY; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | ## Fobidden special characters | ||||||||||||||||||||||||||||
| 191 | 2 | ▶ | unless ( $speChars eq '__ALL__' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | 0 | $password =~ s/[\Q$speChars\E\w]//g; | |||||||||||||||||||||||||||
| 193 | 0 | ▶ | if ($password) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 0 | $self->logger->error( 'Password contains ' | |||||||||||||||||||||||||||
| 195 | . length($password) | ||||||||||||||||||||||||||||
| 196 | . " forbidden character(s): $password" ); | ||||||||||||||||||||||||||||
| 197 | 0 | ▶ | return length($password) > 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | ? PE_PP_NOT_ALLOWED_CHARACTERS | ||||||||||||||||||||||||||||
| 199 | : PE_PP_NOT_ALLOWED_CHARACTER; | ||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 2 | return PE_OK; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 105 | 1; | |||||||||||||||||||||||||||