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 (GitHub) 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.

Example

Registration of the event listener in the extension's Services.yaml:

EXT:my_extension/Configuration/Services.yaml
services:
  # Place here the default dependency injection configuration

  MyVendor\MyExtension\PasswordPolicy\EventListener\MyEventListener:
    tags:
      - name: event.listener
        identifier: 'my-extension/enrich-context-data-event-listener'
Copied!

Read how to configure dependency injection in extensions.

The corresponding event listener class:

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

declare(strict_types=1);

namespace MyVendor\MyExtension\PasswordPolicy\EventListener;

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

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'] ?? '');
        }
    }
}
Copied!

API

class EnrichPasswordValidationContextDataEvent
Fully qualified name
\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 ( )
Returns
TYPO3CMSCorePasswordPolicyValidatorDtoContextData
getUserData ( )
Returns
array
getInitiatingClass ( )
Returns
string