Skip to content

Commit

Permalink
[Data Objects] Password field: added optional minimum password length…
Browse files Browse the repository at this point in the history
… setting
  • Loading branch information
brusch committed Jul 28, 2021
1 parent 43b0963 commit d5f01f8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
Expand Up @@ -174,6 +174,12 @@ pimcore.object.classes.data.password = Class.create(pimcore.object.classes.data.
hideLabel: true,
value: t('width_explanation')
},
{
xtype: "numberfield",
fieldLabel: t("min_length"),
name: "minimumLength",
value: this.datax.minimumLength
},
algorithmsCombo,
salt,
saltCombo
Expand All @@ -193,6 +199,7 @@ pimcore.object.classes.data.password = Class.create(pimcore.object.classes.data.
Ext.apply(this.datax,
{
width: source.datax.width,
minimumLength: source.datax.minimumLength,
algorithm: source.datax.algorithm,
salt: source.datax.salt,
saltlocation: source.datax.saltlocation
Expand Down
1 change: 1 addition & 0 deletions bundles/CoreBundle/Resources/translations/en.extended.json
Expand Up @@ -604,6 +604,7 @@
"custom_login_background_image": "Custom Login Background Image",
"show_charcount": "Show Character Count",
"max_length": "Max Length",
"min_length": "Min Length",
"exclude_from_search_index": "Exclude from Backend Full-Text Search",
"media": "Media",
"encrypt_data": "Encrypt Data",
Expand Down
30 changes: 30 additions & 0 deletions models/DataObject/ClassDefinition/Data/Password.php
Expand Up @@ -84,6 +84,11 @@ class Password extends Data implements ResourcePersistenceAwareInterface, QueryR
*/
public $saltlocation = '';

/**
* @var int|null
*/
public $minimumLength;

/**
* @return string|int
*/
Expand All @@ -107,6 +112,22 @@ public function setWidth($width)
return $this;
}

/**
* @return int|null
*/
public function getMinimumLength(): ?int
{
return $this->minimumLength;
}

/**
* @param int|null $minimumLength
*/
public function setMinimumLength(?int $minimumLength): void
{
$this->minimumLength = $minimumLength;
}

/**
* @param string $algorithm
*/
Expand Down Expand Up @@ -467,4 +488,13 @@ public function getPhpdocReturnType(): ?string
{
return 'string|null';
}

public function checkValidity($data, $omitMandatoryCheck = false, $params = [])
{
if($this->getMinimumLength() && strlen($data) < $this->getMinimumLength()) {
throw new Model\Element\ValidationException('Value in field [ ' . $this->getName() . ' ] is not at least ' . $this->getMinimumLength() . ' characters');
}

parent::checkValidity($data, $omitMandatoryCheck, $params);
}
}

0 comments on commit d5f01f8

Please sign in to comment.