src/Factory/Validator/PasswordVerifyValidatorFactory.php
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $services = $serviceLocator->getServiceLocator();

        /* @var $options InputFilterOptionsInterface */
        $options = $services->get(ModuleOptions::class);

        $userMapper = null;
        $identity   = null;

        if ($services->has($options->getAuthenticationService())) {
            /* @var $authService \Zend\Authentication\AuthenticationServiceInterface */
            $authService = $services->get($options->getAuthenticationService());

            if ($authService->hasIdentity()) {
                /* @var $userMapper \CmsUser\Persistence\UserMapperInterface */
                $userMapper = $services->get('MapperManager')->get($options->getUserEntityClass());
                /* @var $identity \CmsUser\Mapping\UserInterface */
                $identity = $authService->getIdentity();
            }
        }

        $validatorChain = new ValidatorChain();

        $validatorChain->attachByName('Callback', [
            'messages' => [
                Callback::INVALID_VALUE => 'Incorrect password verification',
            ],
            'callback' => function($value, $context = []) use ($userMapper, $identity) {
                if (isset($context['password'])) {
                    return $value === $context['password'];
                } elseif ($userMapper && $identity && $identity instanceof PasswordableInterface) {
                    return $userMapper->getPasswordService()->verify($value, $identity->getPassword());
                }
                return false;
            },
        ], true);

        return $validatorChain;
    }
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $services = $serviceLocator->getServiceLocator();

        /* @var $options InputFilterOptionsInterface */
        $options = $services->get(ModuleOptions::class);

        $userMapper = null;
        $identity   = null;

        if ($services->has($options->getAuthenticationService())) {
            /* @var $authService \Zend\Authentication\AuthenticationServiceInterface */
            $authService = $services->get($options->getAuthenticationService());

            if ($authService->hasIdentity()) {
                /* @var $userMapper \CmsUser\Persistence\UserMapperInterface */
                $userMapper = $services->get('MapperManager')->get($options->getUserEntityClass());
                /* @var $identity \CmsUser\Mapping\UserInterface */
                $identity = $authService->getIdentity();
            }
        }

        $validatorChain = new ValidatorChain();

        $validatorChain->attachByName('Callback', [
            'messages' => [
                Callback::INVALID_VALUE => 'Incorrect password verification',
            ],
            'callback' => function($value, $context = []) use ($userMapper, $identity) {
                if (isset($context['password'])) {
                    return $value === $context['password'];
                } elseif ($userMapper && $identity && $identity instanceof PasswordableInterface) {
                    return $userMapper->getPasswordService()->verify($value, $identity->getPassword());
                }
                return false;
            },
        ], true);

        return $validatorChain;
    }
{@inheritDoc}

@return ValidatorInterface