From d5f01f8a9633d0473d66a8db3add94ba62331c8e Mon Sep 17 00:00:00 2001 From: Bernhard Rusch Date: Wed, 28 Jul 2021 11:23:18 +0200 Subject: [PATCH] [Data Objects] Password field: added optional minimum password length setting --- .../pimcore/object/classes/data/password.js | 7 +++++ .../Resources/translations/en.extended.json | 1 + .../ClassDefinition/Data/Password.php | 30 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/classes/data/password.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/classes/data/password.js index da08e6b8a6d..428e0ee297d 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/object/classes/data/password.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/classes/data/password.js @@ -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 @@ -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 diff --git a/bundles/CoreBundle/Resources/translations/en.extended.json b/bundles/CoreBundle/Resources/translations/en.extended.json index a9766c761f8..2537e874996 100644 --- a/bundles/CoreBundle/Resources/translations/en.extended.json +++ b/bundles/CoreBundle/Resources/translations/en.extended.json @@ -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", diff --git a/models/DataObject/ClassDefinition/Data/Password.php b/models/DataObject/ClassDefinition/Data/Password.php index 32710f73369..15d4b450b1d 100644 --- a/models/DataObject/ClassDefinition/Data/Password.php +++ b/models/DataObject/ClassDefinition/Data/Password.php @@ -84,6 +84,11 @@ class Password extends Data implements ResourcePersistenceAwareInterface, QueryR */ public $saltlocation = ''; + /** + * @var int|null + */ + public $minimumLength; + /** * @return string|int */ @@ -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 */ @@ -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); + } }