FIX #2496 `ConfirmedPasswordField` mismatch passwords saved

Fixes #2496

Also fixes another issue where 'Password' is hard coded as field name in `validate()`
This commit is contained in:
Daniel Hensby 2013-10-21 20:31:40 +01:00 committed by Daniel Hensby
parent 8ef14d2df4
commit 2a6f1f1949
1 changed files with 16 additions and 7 deletions

View File

@ -243,8 +243,12 @@ class ConfirmedPasswordField extends FormField {
// If $data is a DataObject, don't use the value, since it's a hashed value
if ($data && $data instanceof DataObject) $value = '';
//store this for later
$oldValue = $this->value;
if(is_array($value)) {
if($value['_Password'] || (!$value['_Password'] && !$this->canBeEmpty)) {
//only set the value if it's valid!
if($this->validate(RequiredFields::create())) {
$this->value = $value['_Password'];
}
@ -258,11 +262,14 @@ class ConfirmedPasswordField extends FormField {
}
}
$this->children->fieldByName($this->getName() . '[_Password]')
->setValue($this->value);
//looking up field by name is expensive, so lets check it needs to change
if ($oldValue != $this->value) {
$this->children->fieldByName($this->getName() . '[_Password]')
->setValue($this->value);
$this->children->fieldByName($this->getName() . '[_ConfirmPassword]')
->setValue($this->value);
$this->children->fieldByName($this->getName() . '[_ConfirmPassword]')
->setValue($this->value);
}
return $this;
}
@ -351,7 +358,9 @@ class ConfirmedPasswordField extends FormField {
}
$limitRegex = '/^.' . $limit . '$/';
if(!empty($value) && !preg_match($limitRegex,$value)) {
$validator->validationError('Password', $errorMsg,
$validator->validationError(
$name,
$errorMsg,
"validation",
false
);
@ -361,7 +370,7 @@ class ConfirmedPasswordField extends FormField {
if($this->requireStrongPassword) {
if(!preg_match('/^(([a-zA-Z]+\d+)|(\d+[a-zA-Z]+))[a-zA-Z0-9]*$/',$value)) {
$validator->validationError(
'Password',
$name,
_t('Form.VALIDATIONSTRONGPASSWORD',
"Passwords must have at least one digit and one alphanumeric character"),
"validation",