mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #2076 from halkyon/passwordvalidator_translate
Allow PasswordValidator to be translated
This commit is contained in:
commit
31cfcdb08e
@ -64,8 +64,14 @@ class PasswordValidator extends Object {
|
|||||||
if($this->minLength) {
|
if($this->minLength) {
|
||||||
if(strlen($password) < $this->minLength) {
|
if(strlen($password) < $this->minLength) {
|
||||||
$valid->error(
|
$valid->error(
|
||||||
sprintf("Password is too short, it must be %s or more characters long.", $this->minLength),
|
sprintf(
|
||||||
"TOO_SHORT"
|
_t(
|
||||||
|
'PasswordValidator.TOOSHORT',
|
||||||
|
'Password is too short, it must be %s or more characters long'
|
||||||
|
),
|
||||||
|
$this->minLength
|
||||||
|
),
|
||||||
|
'TOO_SHORT'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,15 +80,27 @@ class PasswordValidator extends Object {
|
|||||||
$score = 0;
|
$score = 0;
|
||||||
$missedTests = array();
|
$missedTests = array();
|
||||||
foreach($this->testNames as $name) {
|
foreach($this->testNames as $name) {
|
||||||
if(preg_match(self::config()->character_strength_tests[$name], $password)) $score++;
|
if(preg_match(self::config()->character_strength_tests[$name], $password)) {
|
||||||
else $missedTests[] = $name;
|
$score++;
|
||||||
|
} else {
|
||||||
|
$missedTests[] = _t(
|
||||||
|
'PasswordValidator.STRENGTHTEST' . strtoupper($name),
|
||||||
|
$name,
|
||||||
|
'The user needs to add this to their password for more complexity'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($score < $this->minScore) {
|
if($score < $this->minScore) {
|
||||||
$valid->error(
|
$valid->error(
|
||||||
"You need to increase the strength of your passwords by adding some of the following characters: "
|
sprintf(
|
||||||
. implode(", ", $missedTests),
|
_t(
|
||||||
"LOW_CHARACTER_STRENGTH"
|
'PasswordValidator.LOWCHARSTRENGTH',
|
||||||
|
'Please increase password strength by adding some of the following characters: %s'
|
||||||
|
),
|
||||||
|
implode(', ', $missedTests)
|
||||||
|
),
|
||||||
|
'LOW_CHARACTER_STRENGTH'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,15 +109,18 @@ class PasswordValidator extends Object {
|
|||||||
$previousPasswords = DataObject::get(
|
$previousPasswords = DataObject::get(
|
||||||
"MemberPassword",
|
"MemberPassword",
|
||||||
"\"MemberID\" = $member->ID",
|
"\"MemberID\" = $member->ID",
|
||||||
"\"Created\" DESC, \"ID\" Desc",
|
"\"Created\" DESC, \"ID\" DESC",
|
||||||
"",
|
"",
|
||||||
$this->historicalPasswordCount
|
$this->historicalPasswordCount
|
||||||
);
|
);
|
||||||
if($previousPasswords) foreach($previousPasswords as $previousPasswords) {
|
if($previousPasswords) foreach($previousPasswords as $previousPasswords) {
|
||||||
if($previousPasswords->checkPassword($password)) {
|
if($previousPasswords->checkPassword($password)) {
|
||||||
$valid->error(
|
$valid->error(
|
||||||
"You've already used that password in the past, please choose a new password",
|
_t(
|
||||||
"PREVIOUS_PASSWORD"
|
'PasswordValidator.PREVPASSWORD',
|
||||||
|
'You\'ve already used that password in the past, please choose a new password'
|
||||||
|
),
|
||||||
|
'PREVIOUS_PASSWORD'
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user