|
7 | 7 | namespace Magento\User\Model;
|
8 | 8 |
|
9 | 9 | use Laminas\Validator\Identical;
|
| 10 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 11 | +use Magento\Framework\App\ObjectManager; |
10 | 12 | use Magento\Framework\Validator\DataObject;
|
11 | 13 | use Magento\Framework\Validator\EmailAddress;
|
12 | 14 | use Magento\Framework\Validator\NotEmpty;
|
|
22 | 24 | class UserValidationRules
|
23 | 25 | {
|
24 | 26 | /**
|
25 |
| - * Minimum length of admin password |
| 27 | + * Configuration path for minimum admin password length |
26 | 28 | */
|
27 |
| - public const MIN_PASSWORD_LENGTH = 12; |
| 29 | + private const XML_PATH_MINIMUM_PASSWORD_LENGTH = 'admin/security/minimum_password_length'; |
| 30 | + |
| 31 | + /** |
| 32 | + * Minimum length of admin password (fallback) |
| 33 | + */ |
| 34 | + public const MIN_PASSWORD_LENGTH = 7; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var ScopeConfigInterface |
| 38 | + */ |
| 39 | + private $scopeConfig; |
| 40 | + |
| 41 | + /** |
| 42 | + * @param ScopeConfigInterface|null $scopeConfig |
| 43 | + */ |
| 44 | + public function __construct(?ScopeConfigInterface $scopeConfig = null) |
| 45 | + { |
| 46 | + $this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Get minimum password length from configuration |
| 51 | + * |
| 52 | + * @return int |
| 53 | + */ |
| 54 | + private function getMinimumPasswordLength(): int |
| 55 | + { |
| 56 | + $configValue = $this->scopeConfig->getValue(self::XML_PATH_MINIMUM_PASSWORD_LENGTH); |
| 57 | + return $configValue ? (int) $configValue : self::MIN_PASSWORD_LENGTH; |
| 58 | + } |
28 | 59 |
|
29 | 60 | /**
|
30 | 61 | * Adds validation rule for user first name, last name, username and email
|
@@ -83,7 +114,7 @@ public function addPasswordRules(DataObject $validator)
|
83 | 114 | {
|
84 | 115 | $passwordNotEmpty = new NotEmpty();
|
85 | 116 | $passwordNotEmpty->setMessage(__('Password is required field.'), NotEmpty::IS_EMPTY);
|
86 |
| - $minPassLength = self::MIN_PASSWORD_LENGTH; |
| 117 | + $minPassLength = $this->getMinimumPasswordLength(); |
87 | 118 | $passwordLength = new StringLength(['min' => $minPassLength, 'encoding' => 'UTF-8']);
|
88 | 119 | $passwordLength->setMessage(
|
89 | 120 | __('Your password must be at least %1 characters.', $minPassLength),
|
|
0 commit comments