EnrichPasswordValidationContextDataEvent

New in version 12.3.

The PSR-14 event \TYPO3\CMS\Core\PasswordPolicy\Event\EnrichPasswordValidationContextDataEvent allows extensions to enrich the EXT:core/Classes/PasswordPolicy/Validator/Dto/ContextData.php DTO used in the password policy validation.

The PSR-14 event is dispatched in all classes where a user password is validated against the globally configured password policy.

Note

The user data returned by the method getUserData() will include user data available from the initiating class only. Therefore, event listeners should always consider the initiating class name when accessing data from getUserData(). If specific user data is not available via getUserData(), it can possibly be retrieved by a custom database query (for example, data from the user table in the password reset process by fetching the user with the uid given in getUserData() array).

Example

EXT:my_extension/Classes/Redirects/EventListener/MyEventListener.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\PasswordPolicy\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\PasswordPolicy\Event\EnrichPasswordValidationContextDataEvent;

#[AsEventListener(
    identifier: 'my-extension/enrich-context-data-event-listener'
)]
final class MyEventListener
{
    public function __invoke(EnrichPasswordValidationContextDataEvent $event): void
    {
        if ($event->getInitiatingClass() === DataHandler::class) {
            $event->getContextData()->setData('currentMiddleName', $event->getUserData()['middle_name'] ?? '');
            $event->getContextData()->setData('currentEmail', $event->getUserData()['email'] ?? '');
        }
    }
}

New in version 13.0: The PHP attribute \TYPO3\CMS\Core\Attribute\AsEventListener has been introduced to tag a PHP class as an event listener. Alternatively, or if you need to be compatible with older TYPO3 versions, you can also register an event listener via the Configuration/Services.yaml file. Switch to an older version of this page for an example or have a look at the section Implementing an event listener in your extension.

API

class TYPO3\CMS\Core\PasswordPolicy\Event\EnrichPasswordValidationContextDataEvent

Event is dispatched before the ContextData DTO is passed to the password policy validator.

Note, that the $userData array will include user data available from the initiating class only. Event listeners should therefore always consider the initiating class name when accessing data from getUserData().

getContextData()
Return type

TYPO3\CMS\Core\PasswordPolicy\Validator\Dto\ContextData

getUserData()
Return type

array

getInitiatingClass()
Return type

string