‪TYPO3CMS  ‪main
AbstractPasswordValidator.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ServerRequestInterface;
26 
31 {
32  private array ‪$requirements = [];
33  private array ‪$errorMessages = [];
34 
35  public function ‪__construct(protected array $options = [])
36  {
38  }
39 
44  public function ‪initializeRequirements(): void {}
45 
54  public function ‪validate(string $password, ?‪ContextData $contextData = null): bool
55  {
56  return false;
57  }
58 
62  final public function ‪getRequirements(): array
63  {
64  return array_map(htmlspecialchars(...), $this->requirements);
65  }
66 
73  final protected function ‪addRequirement(string ‪$identifier, string $message): void
74  {
75  $classIdentifier = $this->‪getClassId();
76  $this->requirements[$classIdentifier . ‪$identifier] = $message;
77  }
78 
82  final public function ‪getErrorMessages(): array
83  {
85  }
86 
93  final protected function ‪addErrorMessage(string ‪$identifier, string $errorMessage): void
94  {
95  $classIdentifier = $this->‪getClassId();
96  $this->errorMessages[$classIdentifier . ‪$identifier] = $errorMessage;
97  }
98 
99  private function ‪getClassId(): string
100  {
101  $classParts = explode('\\', static::class);
102  return lcfirst(end($classParts)) . '.';
103  }
104 
106  {
107  $request = ‪$GLOBALS['TYPO3_REQUEST'] ?? null;
108  if ($request instanceof ServerRequestInterface && ‪ApplicationType::fromRequest($request)->isFrontend()) {
109  $languageServiceFactory = GeneralUtility::makeInstance(LanguageServiceFactory::class);
110  return $languageServiceFactory->createFromSiteLanguage($request->getAttribute('language')
111  ?? $request->getAttribute('site')->getDefaultLanguage());
112  }
113 
114  if ((‪$GLOBALS['LANG'] ?? null) instanceof ‪LanguageService) {
115  return ‪$GLOBALS['LANG'];
116  }
117 
118  $languageServiceFactory = GeneralUtility::makeInstance(LanguageServiceFactory::class);
119  return $languageServiceFactory->createFromUserPreferences(‪$GLOBALS['BE_USER'] ?? null);
120  }
121 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\PasswordPolicy\Validator\AbstractPasswordValidator\$requirements
‪array $requirements
Definition: AbstractPasswordValidator.php:32
‪TYPO3\CMS\Core\PasswordPolicy\Validator\AbstractPasswordValidator\$errorMessages
‪array $errorMessages
Definition: AbstractPasswordValidator.php:33
‪TYPO3\CMS\Core\PasswordPolicy\Validator\AbstractPasswordValidator\getClassId
‪getClassId()
Definition: AbstractPasswordValidator.php:99
‪TYPO3\CMS\Core\PasswordPolicy\Validator\AbstractPasswordValidator\validate
‪validate(string $password, ?ContextData $contextData=null)
Definition: AbstractPasswordValidator.php:54
‪TYPO3\CMS\Core\PasswordPolicy\Validator\AbstractPasswordValidator\addErrorMessage
‪addErrorMessage(string $identifier, string $errorMessage)
Definition: AbstractPasswordValidator.php:93
‪TYPO3\CMS\Core\PasswordPolicy\Validator\AbstractPasswordValidator\initializeRequirements
‪initializeRequirements()
Definition: AbstractPasswordValidator.php:44
‪TYPO3\CMS\Core\PasswordPolicy\Validator\AbstractPasswordValidator\getErrorMessages
‪getErrorMessages()
Definition: AbstractPasswordValidator.php:82
‪TYPO3\CMS\Core\PasswordPolicy\Validator\AbstractPasswordValidator\getLanguageService
‪getLanguageService()
Definition: AbstractPasswordValidator.php:105
‪TYPO3\CMS\Core\PasswordPolicy\Validator\AbstractPasswordValidator\__construct
‪__construct(protected array $options=[])
Definition: AbstractPasswordValidator.php:35
‪TYPO3\CMS\Core\PasswordPolicy\Validator\AbstractPasswordValidator\getRequirements
‪getRequirements()
Definition: AbstractPasswordValidator.php:62
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\PasswordPolicy\Validator\AbstractPasswordValidator
Definition: AbstractPasswordValidator.php:31
‪TYPO3\CMS\Core\Http\fromRequest
‪@ fromRequest
Definition: ApplicationType.php:67
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\PasswordPolicy\Validator
Definition: AbstractPasswordValidator.php:18
‪TYPO3\CMS\Core\PasswordPolicy\Validator\AbstractPasswordValidator\addRequirement
‪addRequirement(string $identifier, string $message)
Definition: AbstractPasswordValidator.php:73
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37
‪TYPO3\CMS\Core\Http\ApplicationType
‪ApplicationType
Definition: ApplicationType.php:56
‪TYPO3\CMS\Core\PasswordPolicy\Validator\Dto\ContextData
Definition: ContextData.php:28