mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
8ef14d2df4
commit
2a6f1f1949
@ -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 is a DataObject, don't use the value, since it's a hashed value
|
||||||
if ($data && $data instanceof DataObject) $value = '';
|
if ($data && $data instanceof DataObject) $value = '';
|
||||||
|
|
||||||
|
//store this for later
|
||||||
|
$oldValue = $this->value;
|
||||||
|
|
||||||
if(is_array($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'];
|
$this->value = $value['_Password'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,11 +262,14 @@ class ConfirmedPasswordField extends FormField {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->children->fieldByName($this->getName() . '[_Password]')
|
//looking up field by name is expensive, so lets check it needs to change
|
||||||
->setValue($this->value);
|
if ($oldValue != $this->value) {
|
||||||
|
$this->children->fieldByName($this->getName() . '[_Password]')
|
||||||
|
->setValue($this->value);
|
||||||
|
|
||||||
$this->children->fieldByName($this->getName() . '[_ConfirmPassword]')
|
$this->children->fieldByName($this->getName() . '[_ConfirmPassword]')
|
||||||
->setValue($this->value);
|
->setValue($this->value);
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -351,7 +358,9 @@ class ConfirmedPasswordField extends FormField {
|
|||||||
}
|
}
|
||||||
$limitRegex = '/^.' . $limit . '$/';
|
$limitRegex = '/^.' . $limit . '$/';
|
||||||
if(!empty($value) && !preg_match($limitRegex,$value)) {
|
if(!empty($value) && !preg_match($limitRegex,$value)) {
|
||||||
$validator->validationError('Password', $errorMsg,
|
$validator->validationError(
|
||||||
|
$name,
|
||||||
|
$errorMsg,
|
||||||
"validation",
|
"validation",
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@ -361,7 +370,7 @@ class ConfirmedPasswordField extends FormField {
|
|||||||
if($this->requireStrongPassword) {
|
if($this->requireStrongPassword) {
|
||||||
if(!preg_match('/^(([a-zA-Z]+\d+)|(\d+[a-zA-Z]+))[a-zA-Z0-9]*$/',$value)) {
|
if(!preg_match('/^(([a-zA-Z]+\d+)|(\d+[a-zA-Z]+))[a-zA-Z0-9]*$/',$value)) {
|
||||||
$validator->validationError(
|
$validator->validationError(
|
||||||
'Password',
|
$name,
|
||||||
_t('Form.VALIDATIONSTRONGPASSWORD',
|
_t('Form.VALIDATIONSTRONGPASSWORD',
|
||||||
"Passwords must have at least one digit and one alphanumeric character"),
|
"Passwords must have at least one digit and one alphanumeric character"),
|
||||||
"validation",
|
"validation",
|
||||||
|
Loading…
Reference in New Issue
Block a user