getPassword example

final class SinchTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): SinchTransport
    {
        $scheme = $dsn->getScheme();

        if ('sinch' !== $scheme) {
            throw new UnsupportedSchemeException($dsn, 'sinch', $this->getSupportedSchemes());
        }

        $accountSid = $this->getUser($dsn);
        $authToken = $this->getPassword($dsn);
        $from = $dsn->getRequiredOption('from');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new SinchTransport($accountSid$authToken$from$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    protected function getSupportedSchemes(): array
    {
        return ['sinch'];
    }
}
$form_state->setValue('pass', $pass);
    $form_state->setValue('init', $form_state->getValue('mail'));

    parent::submitForm($form$form_state);
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $account = $this->entity;
    $pass = $account->getPassword();
    $admin = $form_state->getValue('administer_users');
    $notify = !$form_state->isValueEmpty('notify');

    // Save has no return value so this cannot be tested.     // Assume save has gone through correctly.     $account->save();

    $form_state->set('user', $account);
    $form_state->setValue('uid', $account->id());

    $this->logger('user')->info('New user: %name %email.', ['%name' => $form_state->getValue('name'), '%email' => '<' . $form_state->getValue('mail') . '>', 'type' => $account->toLink($this->t('Edit'), 'edit-form')->toString()]);

    

  protected function assertEntity(string $id, string $label, string $mail, string $password, int $created, int $access, int $login, bool $blocked, string $entity_langcode, string $prefered_langcode, string $timezone, string $init, array $roles, ?array $field_integer$field_file_target_id = FALSE, bool $has_picture = FALSE): void {
    /** @var \Drupal\user\UserInterface $user */
    $user = User::load($id);
    $this->assertInstanceOf(UserInterface::class$user);
    $this->assertSame($label$user->label());
    $this->assertSame($mail$user->getEmail());
    $this->assertSame($password$user->getPassword());
    $this->assertSame($created(int) $user->getCreatedTime());
    $this->assertSame($access(int) $user->getLastAccessedTime());
    $this->assertSame($login(int) $user->getLastLoginTime());
    $this->assertNotSame($blocked(bool) $user->isBlocked());

    // Ensure the user's langcode, preferred_langcode and     // preferred_admin_langcode are valid.     // $user->getPreferredLangcode() might fallback to default language if the     // user preferred language is not configured on the site. We just want to     // test if the value was imported correctly.     $language_manager = $this->container->get('language_manager');
    


    private static function hasUserChanged(UserInterface $originalUser, TokenInterface $refreshedToken): bool
    {
        $refreshedUser = $refreshedToken->getUser();

        if ($originalUser instanceof EquatableInterface) {
            return !(bool) $originalUser->isEqualTo($refreshedUser);
        }

        if ($originalUser instanceof PasswordAuthenticatedUserInterface || $refreshedUser instanceof PasswordAuthenticatedUserInterface) {
            if (!$originalUser instanceof PasswordAuthenticatedUserInterface || !$refreshedUser instanceof PasswordAuthenticatedUserInterface || $originalUser->getPassword() !== $refreshedUser->getPassword()) {
                return true;
            }

            if ($originalUser instanceof LegacyPasswordAuthenticatedUserInterface xor $refreshedUser instanceof LegacyPasswordAuthenticatedUserInterface) {
                return true;
            }

            if ($originalUser instanceof LegacyPasswordAuthenticatedUserInterface && $refreshedUser instanceof LegacyPasswordAuthenticatedUserInterface && $originalUser->getSalt() !== $refreshedUser->getSalt()) {
                return true;
            }
        }

        
final class MessageMediaTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): MessageMediaTransport
    {
        $scheme = $dsn->getScheme();

        if ('messagemedia' !== $scheme) {
            throw new UnsupportedSchemeException($dsn, 'messagemedia', $this->getSupportedSchemes());
        }

        $apiKey = $this->getUser($dsn);
        $apiSecret = $this->getPassword($dsn);
        $from = $dsn->getOption('from');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new MessageMediaTransport($apiKey$apiSecret$from$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    protected function getSupportedSchemes(): array
    {
        return ['messagemedia'];
    }
}


        return $this->loadUser($identifier$entry);
    }

    public function refreshUser(UserInterface $user): UserInterface
    {
        if (!$user instanceof LdapUser) {
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
        }

        return new LdapUser($user->getEntry()$user->getUserIdentifier()$user->getPassword()$user->getRoles()$user->getExtraFields());
    }

    /** * @final */
    public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void
    {
        if (!$user instanceof LdapUser) {
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
        }

        
final class KazInfoTehTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): TransportInterface
    {
        $scheme = $dsn->getScheme();

        if ('kaz-info-teh' !== $scheme) {
            throw new UnsupportedSchemeException($dsn, 'kaz-info-teh', $this->getSupportedSchemes());
        }

        $username = $this->getUser($dsn);
        $password = $this->getPassword($dsn);
        $sender = $dsn->getRequiredOption('sender');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new KazInfoTehTransport($username$password$sender$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    protected function getSupportedSchemes(): array
    {
        return ['kaz-info-teh'];
    }
}

final class SesTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): TransportInterface
    {
        $scheme = $dsn->getScheme();
        $region = $dsn->getOption('region');

        if ('ses+smtp' === $scheme || 'ses+smtps' === $scheme) {
            $transport = new SesSmtpTransport($this->getUser($dsn)$this->getPassword($dsn)$region$this->dispatcher, $this->logger, $dsn->getHost());

            if (null !== $pingThreshold = $dsn->getOption('ping_threshold')) {
                $transport->setPingThreshold((int) $pingThreshold);
            }

            return $transport;
        }

        switch ($scheme) {
            case 'ses+api':
                $class = SesApiAsyncAwsTransport::class;
                
public function testUnauthorizedWithPasswordGrantTypeWhenTokenExpired(): void
    {
        $browser = $this->getBrowser();

        $connection = $browser->getContainer()->get(Connection::class);
        $admin = TestUser::createNewTestUser($connection['product:read']);

        $authPayload = [
            'grant_type' => 'password',
            'client_id' => 'administration',
            'username' => $admin->getName(),
            'password' => $admin->getPassword(),
        ];

        $browser->request('POST', '/api/oauth/token', $authPayload);
        static::assertNotFalse($browser->getResponse()->getContent());

        static::assertEquals(Response::HTTP_OK, $browser->getResponse()->getStatusCode());
        $token = \json_decode($browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        static::assertIsString($accessToken = $token['access_token']);

        $userRepository = $this->getContainer()->get('user.repository');

        
final class SmscTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): SmscTransport
    {
        $scheme = $dsn->getScheme();

        if ('smsc' !== $scheme) {
            throw new UnsupportedSchemeException($dsn, 'smsc', $this->getSupportedSchemes());
        }

        $login = $dsn->getUser();
        $password = $dsn->getPassword();
        $from = $dsn->getRequiredOption('from');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();

        return (new SmscTransport($login$password$from$this->client, $this->dispatcher))->setHost($host);
    }

    protected function getSupportedSchemes(): array
    {
        return ['smsc'];
    }
}
public function create(Dsn $dsn): SendberryTransport
    {
        $scheme = $dsn->getScheme();

        if ('sendberry' !== $scheme) {
            throw new UnsupportedSchemeException($dsn, 'sendberry', $this->getSupportedSchemes());
        }

        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new SendberryTransport($this->getUser($dsn)$this->getPassword($dsn)$dsn->getRequiredOption('auth_key')$dsn->getRequiredOption('from')$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

    protected function getSupportedSchemes(): array
    {
        return ['sendberry'];
    }
}
/** * @dataProvider constructProvider */
    public function testConstruct(string $dsnString, string $scheme, string $host, string $user = null, string $password = null, int $port = null, array $options = [], string $path = null)
    {
        $dsn = new Dsn($dsnString);
        $this->assertSame($dsnString$dsn->getOriginalDsn());

        $this->assertSame($scheme$dsn->getScheme());
        $this->assertSame($host$dsn->getHost());
        $this->assertSame($user$dsn->getUser());
        $this->assertSame($password$dsn->getPassword());
        $this->assertSame($port$dsn->getPort());
        $this->assertSame($path$dsn->getPath());
        $this->assertSame($options$dsn->getOptions());
    }

    public static function constructProvider(): iterable
    {
        yield 'simple dsn' => [
            'scheme://localhost',
            'scheme',
            'localhost',
        ];
/** * @dataProvider constructProvider */
    public function testConstruct(string $dsnString, string $scheme, string $host, string $user = null, string $password = null, int $port = null, array $options = [], string $path = null)
    {
        $dsn = new Dsn($dsnString);
        $this->assertSame($dsnString$dsn->getOriginalDsn());

        $this->assertSame($scheme$dsn->getScheme());
        $this->assertSame($host$dsn->getHost());
        $this->assertSame($user$dsn->getUser());
        $this->assertSame($password$dsn->getPassword());
        $this->assertSame($port$dsn->getPort());
        $this->assertSame($path$dsn->getPath());
        $this->assertSame($options$dsn->getOptions());
    }

    public static function constructProvider(): iterable
    {
        yield 'simple dsn' => [
            'scheme://localhost',
            'scheme',
            'localhost',
        ];
// Create a new user and authenticate.     $account = $this->drupalCreateUser([]);
    $password = $account->passRaw;
    $this->drupalLogin($account);
    $this->drupalLogout();

    // Load the stored user. The password hash shouldn't need a rehash.     $user_storage = $this->container->get('entity_type.manager')->getStorage('user');
    $account = User::load($account->id());

    // Check that the stored password doesn't need rehash.     $this->assertFalse($password_hasher->needsRehash($account->getPassword()));

    // The current hashing cost is set to 10 in the container. Increase cost by     // one, by enabling a module containing the necessary container changes.     \Drupal::service('module_installer')->install(['user_custom_pass_hash_params_test']);
    $this->resetAll();
    // Reload the hashing service after container changes.     $password_hasher = $this->container->get('password');

    // Check that the stored password does need rehash.     $this->assertTrue($password_hasher->needsRehash($account->getPassword()));

    
throw new UnexpectedTypeException($password, 'string');
        }

        $user = $this->tokenStorage->getToken()->getUser();

        if (!$user instanceof PasswordAuthenticatedUserInterface) {
            throw new ConstraintDefinitionException(sprintf('The "%s" class must implement the "%s" interface.', PasswordAuthenticatedUserInterface::classget_debug_type($user)));
        }

        $hasher = $this->hasherFactory->getPasswordHasher($user);

        if (null === $user->getPassword() || !$hasher->verify($user->getPassword()$password$user instanceof LegacyPasswordAuthenticatedUserInterface ? $user->getSalt() : null)) {
            $this->context->buildViolation($constraint->message)
                ->setCode(UserPassword::INVALID_PASSWORD_ERROR)
                ->addViolation();
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.