8889841cplugins/mailpoet/vendor-prefixed/symfony/validator/Constraints/NotCompromisedPasswordValidator.php000064400000005015150516022670040112 0ustar00home/clixcotz/tcchp.clix.co.tz/wp-contenthttpClient = $httpClient ?? HttpClient::create(); $this->charset = $charset; $this->enabled = $enabled; $this->endpoint = $endpoint ?? self::DEFAULT_API_ENDPOINT; } public function validate($value, Constraint $constraint) { if (!$constraint instanceof NotCompromisedPassword) { throw new UnexpectedTypeException($constraint, NotCompromisedPassword::class); } if (!$this->enabled) { return; } if (null !== $value && !\is_scalar($value) && !(\is_object($value) && \method_exists($value, '__toString'))) { throw new UnexpectedValueException($value, 'string'); } $value = (string) $value; if ('' === $value) { return; } if ('UTF-8' !== $this->charset) { $value = \mb_convert_encoding($value, 'UTF-8', $this->charset); } $hash = \strtoupper(\sha1($value)); $hashPrefix = \substr($hash, 0, 5); $url = \sprintf($this->endpoint, $hashPrefix); try { $result = $this->httpClient->request('GET', $url)->getContent(); } catch (ExceptionInterface $e) { if ($constraint->skipOnError) { return; } throw $e; } foreach (\explode("\r\n", $result) as $line) { [$hashSuffix, $count] = \explode(':', $line); if ($hashPrefix . $hashSuffix === $hash && $constraint->threshold <= (int) $count) { $this->context->buildViolation($constraint->message)->setCode(NotCompromisedPassword::COMPROMISED_PASSWORD_ERROR)->addViolation(); return; } } } }