mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR Fixed hardcoded error message in PasswordValidator (fixes #5734)
MINOR Added PasswordValidatorTest git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@106687 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
7b90d5e94d
commit
862c5a8602
@ -52,11 +52,16 @@ class PasswordValidator extends Object {
|
||||
$this->historicalPasswordCount = $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $password
|
||||
* @param Member $member
|
||||
* @return ValidationResult
|
||||
*/
|
||||
function validate($password, $member) {
|
||||
$valid = new ValidationResult();
|
||||
|
||||
if($this->minLength) {
|
||||
if(strlen($password) < $this->minLength) $valid->error("Password is too short, it must be 7 or more characters long.", "TOO_SHORT");
|
||||
if(strlen($password) < $this->minLength) $valid->error(sprintf("Password is too short, it must be %s or more characters long.", $this->minLength), "TOO_SHORT");
|
||||
}
|
||||
|
||||
if($this->minScore) {
|
||||
|
44
tests/security/PasswordValidatorTest.php
Normal file
44
tests/security/PasswordValidatorTest.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* @package sapphire
|
||||
* @subpackage tests
|
||||
*/
|
||||
|
||||
class PasswordValidatorTest extends SapphireTest {
|
||||
|
||||
function testValidate() {
|
||||
$v = new PasswordValidator();
|
||||
$r = $v->validate('', new Member());
|
||||
$this->assertTrue($r->valid(), 'Empty password is valid by default');
|
||||
|
||||
$r = $v->validate('mypassword', new Member());
|
||||
$this->assertTrue($r->valid(), 'Non-Empty password is valid by default');
|
||||
}
|
||||
|
||||
function testValidateMinLength() {
|
||||
$v = new PasswordValidator();
|
||||
|
||||
$v->minLength(4);
|
||||
$r = $v->validate('123', new Member());
|
||||
$this->assertFalse($r->valid(), 'Password too short');
|
||||
|
||||
$v->minLength(4);
|
||||
$r = $v->validate('1234', new Member());
|
||||
$this->assertTrue($r->valid(), 'Password long enough');
|
||||
}
|
||||
|
||||
function testValidateMinScore() {
|
||||
$v = new PasswordValidator();
|
||||
$v->characterStrength(3, array("lowercase", "uppercase", "digits", "punctuation"));
|
||||
|
||||
$r = $v->validate('aA', new Member());
|
||||
$this->assertFalse($r->valid(), 'Passing too few tests');
|
||||
|
||||
$r = $v->validate('aA1', new Member());
|
||||
$this->assertTrue($r->valid(), 'Passing enough tests');
|
||||
}
|
||||
|
||||
function testHistoricalPasswordCount() {
|
||||
// TODO
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user