|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| - * Copyright © Magento, Inc. All rights reserved. |
4 |
| - * See COPYING.txt for license details. |
| 3 | + * Copyright 2015 Adobe |
| 4 | + * All Rights Reserved. |
5 | 5 | */
|
6 | 6 |
|
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 |
| 28 | + */ |
| 29 | + private const XML_PATH_MINIMUM_PASSWORD_LENGTH = 'admin/security/minimum_password_length'; |
| 30 | + |
| 31 | + /** |
| 32 | + * Minimum length of admin password (fallback) |
26 | 33 | */
|
27 | 34 | public const MIN_PASSWORD_LENGTH = 7;
|
28 | 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 ? |
| 57 | + $this->scopeConfig->getValue(self::XML_PATH_MINIMUM_PASSWORD_LENGTH) : null; |
| 58 | + |
| 59 | + return $configValue ? (int) $configValue : self::MIN_PASSWORD_LENGTH; |
| 60 | + } |
| 61 | + |
29 | 62 | /**
|
30 | 63 | * Adds validation rule for user first name, last name, username and email
|
31 | 64 | *
|
@@ -83,7 +116,7 @@ public function addPasswordRules(DataObject $validator)
|
83 | 116 | {
|
84 | 117 | $passwordNotEmpty = new NotEmpty();
|
85 | 118 | $passwordNotEmpty->setMessage(__('Password is required field.'), NotEmpty::IS_EMPTY);
|
86 |
| - $minPassLength = self::MIN_PASSWORD_LENGTH; |
| 119 | + $minPassLength = $this->getMinimumPasswordLength(); |
87 | 120 | $passwordLength = new StringLength(['min' => $minPassLength, 'encoding' => 'UTF-8']);
|
88 | 121 | $passwordLength->setMessage(
|
89 | 122 | __('Your password must be at least %1 characters.', $minPassLength),
|
|
0 commit comments