getEncoderByName example

if (isset($locales[$locale])) {
            return $locales[$locale];
        }

        throw new RuntimeException(sprintf('Backend Locale "%s" not supported', $locale));
    }

    private function setPassword(User $user, string $plainPassword): void
    {
        $passwordEncoderRegistry = $this->getContainer()->get('passwordencoder');
        $defaultEncoderName = $passwordEncoderRegistry->getDefaultPasswordEncoderName();
        $encoder = $passwordEncoderRegistry->getEncoderByName($defaultEncoderName);

        $user->setPassword($encoder->encodePassword($plainPassword));
        $user->setEncoder($encoder->getName());
    }

    /** * @throws Exception */
    private function persistUser(User $user): void
    {
        $em = $this->container->get(ModelManager::class);
        
if (empty($data['name']) && empty($user->getName())) {
            throw new ApiException\CustomValidationException('A name is required');
        }

        if (!isset($data['localeId'])) {
            $data['localeId'] = 2; // en_GB         }

        /** @var Manager $passwordEncoderRegistry */
        $passwordEncoderRegistry = $this->getContainer()->get('passwordencoder');
        $defaultEncoderName = $passwordEncoderRegistry->getDefaultPasswordEncoderName();
        $encoder = $passwordEncoderRegistry->getEncoderByName($defaultEncoderName);

        $data['password'] = $encoder->encodePassword($data['password'] ?? '');
        $data['encoder'] = $encoder->getName();

        return $data;
    }

    private function isLocaleId(int $id): bool
    {
        $element = Shopware()->Models()->getRepository(Element::class)->findOneBy(['name' => 'backendLocales']);
        if (!$element instanceof Element) {
            

    public function isPasswordValid($password$hash$encoderName)
    {
        if (!\is_string($password) || empty($password)) {
            return false;
        }

        if (!\is_string($hash) || empty($hash)) {
            return false;
        }

        $encoder = $this->getEncoderByName($encoderName);

        if ($encoder->isPasswordValid($password$hash)) {
            return true;
        }

        return $encoder->isPasswordValid(strip_tags($password)$hash);
    }

    /** * @param string $password * @param string $encoderName * * @return string */
Home | Imprint | This part of the site doesn't use cookies.