定制 jgxvx/cilician 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jgxvx/cilician

Composer 安装命令:

composer require jgxvx/cilician

包简介

PHP Client for haveibeenpwned.com APIs

README 文档

README

Cilician is a PHP client for haveibeenpwned.com APIs (v3).

pipeline status coverage report

Installation

The recommended way to install Cilician is by using Composer:

$ composer require "jgxvx/cilician"

Getting Started

Ideally, the Cilician service is used to interact with the APIs. It is an abstraction layer for the specific API clients and will return convenient result objects or throw exceptions in case of failures.

Following the principle of dependency injection, the Cilician service is passed two API client objects and, optionally, a PSR-16 compliant cache implementation.

Both API clients expect a Guzzle HTTP client as their constructor parameter. The HaveIBeenPwnedApiClient also expects a Have I Been Pwned API key.

$hibpClient = new HaveIBeenPwnedApiClient(new \GuzzleHttp\Client(['base_uri' => HaveIBeenPwnedApiClient::BASE_URI]), 'your-api-key');
$ppClient   = new PwnedPasswordsApiClient(new \GuzzleHttp\Client(['base_uri' => PwnedPasswordsApiClient::BASE_URI]));
$cilician   = new Cilician($hibpClient, $ppClient);

Checking Passwords

To check if a password has appeared in a data breach:

$result = $cilician->checkPassword('12345678');

if ($result->isPwned()) {
    // Handle failure case...
    echo "The password you've chosen has appeared {$result->getCount()} times in data breaches. Do not use it.";
} else {
    // Handle success case...
    echo "All good!";
}

API Documentation

Getting All Breaches for an Account

To retrieve a list of all breaches a particular account has been involved in:

$result = $cilician->getBreachesForAccount('john@doe.com');

if ($result->isPwned()) {
    echo "Your account has appeared in the following breaches:" . PHP_EOL;
    
    foreach ($result->getBreaches() as $breach) {
        echo $breach->getName() . PHP_EOL;
    }
}

The getBreachesForAccount method returns an array of BreachModel instances -- value objects representing the API's breach model.

To narrow down the list, a filter object can be passed as a second argument:

$filter = new BreachFilter(['domain' => 'adobe.com']);
$result = $cilician->getBreachesForAccount('john@doe.com', $filter);

API Documentation

Getting All Breached Sites

To retrieve a list of all breached sites:

$result = $cilician->getBreachedSites();

foreach ($result->getBreaches() as $breach) {
    echo $breach->getName() . PHP_EOL;
}

To narrow down the list, a filter object can be passed to the getBreachedSites method:

$filter = new BreachFilter(['domain' => 'adobe.com']);
$result = $cilician->getBreachedSites($filter);

API Documentation

Getting a Single Breached Site

To retrieve a single breached site:

$result = $cilician->getBreachedSite('Adobe');

if ($result->isPwned()) {
    $breach = $result->getBreaches()[0]; // Safe, as isPwned() only returns true if there is at least one breach.
}

API Documentation

Getting All Available Data Classes

To retrieve all data classes:

$result = $cilician->getDataClasses();

foreach ($result->getDataClasses() as $dataClass) {
    echo $dataClass . PHP_EOL; // Data classes are strings
}

API Documentation

Getting All Pastes for an Account

To retrieve all pastes for an account:

$result = $cilician->getPastesForAccount('john@doe.com');

foreach ($result->getPastes() as $paste) {
    echo $paste->getName() . PHP_EOL;
}

The getPastesForAccount method returns an array of PasteModel instances -- value objects representing the API's paste model.

API Documentation

Filtering

When searching for breaches, a filter can specified to narrow down the search.

Currently, the breach filter supports two parameters:

  • domain -- A domain name string. Default is null.
  • includeUnverified -- Whether unverified breaches should be included. Default is false.

The parameters can either be passed to the filter's constructor as an array, or set by setter methods:

$filter = new BreachFilter(['domain' => 'adobe.com', 'includeUnverified' => true]);

// or

$filter = new BreachFilter();
$filter
    ->setDomain('adobe.com')
    ->setIncludeUnverified(true);

Caching

If the application uses a PSR-16 compliant caching system, the cache can be passed to Cilician as a third constructor parameter. Cilician will then automatically cache responses using the caching system's default TTL.

If a PSR-6 compliant cache is used, it can be converted to PSR-16 with php-cache/simple-cache-bridge or similar.

License

Cilician is open source software published under the MIT license. Please refer to the LICENSE file for further information.

Contributing

We appreciate your help! To contribute, please read the Contribution Guidelines and our Code of Conduct.

jgxvx/cilician 适用场景与选型建议

jgxvx/cilician 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.77k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 09 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「security」 「api client」 「passwords」 「privacy」 「haveibeenpwned」 「data breach」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jgxvx/cilician 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jgxvx/cilician 我们能提供哪些服务?
定制开发 / 二次开发

基于 jgxvx/cilician 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 9.77k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 9
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-29