password_get_info example

KeyValuePair $data,
        WriteParameterBag $parameters
    ): \Generator {
        if (!$field instanceof PasswordField) {
            throw DataAbstractionLayerException::invalidSerializerField(PasswordField::class$field);
        }

        $this->validateIfNeeded($field$existence$data$parameters);

        $value = $data->getValue();
        if ($value) {
            $info = password_get_info($value);
            // if no password algorithm is detected, it might be plain text which needs to be encoded.             // otherwise, passthrough the possibly encoded string             if (!$info['algo']) {
                $value = password_hash((string) $value$field->getAlgorithm()$field->getHashOptions());
            }
        }

        yield $field->getStorageName() => $value;
    }

    public function decode(Field $field, mixed $value): ?string
    {
 else {
            $this->systemConfigService->expects(static::never())->method('getInt');
        }

        $this->validator
            ->expects(static::exactly(\count($constraints)))->method('validate')
            ->willReturn($constraintViolations);

        $result = $this->serializer->encode($field$existence$kv$params)->current();

        if ($inputPassword) {
            $inputPasswordHashed = !empty(password_get_info($inputPassword)['algo']);

            if ($inputPasswordHashed) {
                static::assertEquals($inputPassword$result);
            } else {
                static::assertTrue(password_verify($inputPassword$result));
            }
        }
    }

    /** * @return iterable<string, array<int|string|array<int, Constraint>|bool|null>> */
Home | Imprint | This part of the site doesn't use cookies.