encodePassword example

if (!empty($id)) {
            /** @var User $user */
            $user = $this->getUserRepository()->find((int) $id);
        } else {
            $user = new User();
            $isNewUser = true;
        }

        $params = $this->Request()->getParams();
        if (!empty($params['password'])) {
            $params['encoder'] = $this->manager->getDefaultPasswordEncoderName();
            $params['password'] = $this->manager->encodePassword($params['password']$params['encoder']);
        } else {
            unset($params['password']);
        }

        $user->fromArray($params);

        $this->modelManager->persist($user);
        $this->modelManager->flush();

        if ($isNewUser) {
            $sql = 'INSERT INTO `s_core_widget_views` (`widget_id`, `auth_id`) VALUES ((SELECT id FROM `s_core_widgets` WHERE `name` = :widgetName LIMIT 1), :userId);';
            
$this->eventManager->notify(
            'Shopware_Modules_Admin_Login_Successful',
            ['subject' => $this, 'email' => $email, 'password' => $password, 'user' => $getUser]
        );

        $newHash = '';
        $liveMigration = $this->config->offsetGet('liveMigration');
        $defaultEncoderName = $this->passwordEncoder->getDefaultPasswordEncoderName();

        // Do not allow live migration when the password is pre-hashed         if ($liveMigration && !$isPreHashed && $encoderName !== $defaultEncoderName) {
            $newHash = $this->passwordEncoder->encodePassword($plaintext$defaultEncoderName);
            $encoderName = $defaultEncoderName;
        }

        if (empty($newHash)) {
            $newHash = $this->passwordEncoder->reencodePassword($plaintext$hash$encoderName);
        }

        $userId = (int) $getUser['id'];

        if (!empty($newHash) && $newHash !== $hash) {
            $hash = $newHash;
            
if ($this->firstLogin === null) {
            $this->firstLogin = new DateTime();
        }
        if ($this->lastLogin === null) {
            $this->lastLogin = new DateTime();
        }

        if (!empty($this->rawPassword)) {
            $this->hashPassword = $this->rawPassword;
        } elseif (!empty($this->password)) {
            $this->encoderName = Shopware()->PasswordEncoder()->getDefaultPasswordEncoderName();
            $this->hashPassword = Shopware()->PasswordEncoder()->encodePassword($this->password, $this->encoderName);
        }
    }

    /** * Event listener method which is fired when the model is updated. * * @ORM\PreUpdate() * * @throws LogicException (See AttributeCleanerTrait) */
    public function onUpdate()
    {
/** * Used for updating to new algorithm for the future * * @param string $plaintext * @param string $defaultEncoderName * * @return void */
    public function updateHash($plaintext$defaultEncoderName)
    {
        $newHash = Shopware()->PasswordEncoder()->encodePassword($plaintext$defaultEncoderName);

        $this->_zendDb->update(
            $this->_tableName,
            ['encoder' => $defaultEncoderName$this->_credentialColumn => $newHash],
            $this->_zendDb->quoteInto(
                $this->_zendDb->quoteIdentifier($this->_identityColumn, true) . ' = ?',
                $this->_identity
            )
        );
    }

    

    public function encodePassword($password$encoderName)
    {
        if (!\is_string($password) || empty($password)) {
            throw new DomainException('This Password can not be encoded');
        }

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

        $encodedPassword = $encoder->encodePassword($password);

        if (!\is_string($encodedPassword)) {
            throw new DomainException(sprintf('The password could not be encoded by %s.', $encoderName));
        }

        return $encodedPassword;
    }

    /** * @param string $password * @param string $hash * @param string $encoderName * * @return string */


        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);
        $em->persist($user);
        $em->flush($user);
    }


        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) {
            return false;
        }

        
            $customer->setFirstLogin(null);
            $customer->setLastLogin(null);
            $customer->setDoubleOptinEmailSentDate(new DateTime());
        }

        // Password validation         if ($customer->getPassword()) {
            $customer->setEncoderName(
                $this->passwordManager->getDefaultPasswordEncoderName()
            );
            $customer->setPassword(
                $this->passwordManager->encodePassword(
                    $customer->getPassword(),
                    $customer->getEncoderName()
                )
            );
        }

        // Account mode validation         if ($customer->getAccountMode() == Customer::ACCOUNT_MODE_FAST_LOGIN) {
            $customer->setPassword(md5(uniqid((string) rand())));
            $customer->setEncoderName('md5');
        }

        
Home | Imprint | This part of the site doesn't use cookies.