diff --git a/_config.php b/_config.php index cea1650..470a726 100644 --- a/_config.php +++ b/_config.php @@ -12,8 +12,6 @@ use SilverStripe\Core\Environment; use SilverStripe\HybridSessions\HybridSession; use SilverStripe\i18n\i18n; -use SilverStripe\Security\Member; -use SilverStripe\Security\PasswordValidator; // set the system locale to en_GB. This also means locale dropdowns // and date formatting etc will default to this locale. Note there is no @@ -25,12 +23,6 @@ Environment::setEnv('WKHTMLTOPDF_BINARY', '/usr/local/bin/wkhtmltopdf'); } -// Configure password strength requirements -$pwdValidator = new PasswordValidator(); -$pwdValidator->setMinTestScore(3); -$pwdValidator->setTestNames(["lowercase", "uppercase", "digits", "punctuation"]); -Member::set_password_validator($pwdValidator); - // Automatically configure session key for activedr with hybridsessions module if (Environment::getEnv('CWP_INSTANCE_DR_TYPE') && Environment::getEnv('CWP_INSTANCE_DR_TYPE') === 'active' diff --git a/_config/security.yml b/_config/security.yml index f57c61f..1fce460 100644 --- a/_config/security.yml +++ b/_config/security.yml @@ -1,3 +1,26 @@ +--- +Name: cwppasswordstrength +--- +# In the case someone uses `new PasswordValidator` instead of Injector, provide some safe defaults through config. +# Test names will not be set however, as it is not configurable. +SilverStripe\Security\PasswordValidator: + min_length: 10 + min_test_score: 3 + historic_count: 6 +# Set strength tests and requirements in line with NZISM +# Injector is used by default for Member password validation +SilverStripe\Core\Injector\Injector: + SilverStripe\Security\PasswordValidator: + properties: + MinLength: 10 + MinTestScore: 3 + HistoricCount: 6 + TestNames: + - lowercase + - uppercase + - digits + - punctuation + --- Name: cwpsecurity After: '#canonicalurls' diff --git a/tests/PasswordStrengthTest.php b/tests/PasswordStrengthTest.php new file mode 100644 index 0000000..84d158b --- /dev/null +++ b/tests/PasswordStrengthTest.php @@ -0,0 +1,55 @@ +assertGreaterThanOrEqual(10, $passwordValidator->getMinLength()); + } + + public function testMinTestScore() + { + $passwordValidator = Member::password_validator(); + $this->assertGreaterThanOrEqual(3, $passwordValidator->getMinTestScore()); + } + + public function testHistoricCheckCount() + { + $passwordValidator = Member::password_validator(); + $this->assertGreaterThanOrEqual(6, $passwordValidator->getHistoricCount()); + } + + public function testTestNamesInclude() + { + $passwordValidator = Member::password_validator(); + $this->assertContains('lowercase', $passwordValidator->getTestNames()); + $this->assertContains('uppercase', $passwordValidator->getTestNames()); + $this->assertContains('digits', $passwordValidator->getTestNames()); + $this->assertContains('punctuation', $passwordValidator->getTestNames()); + } +}