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).
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!";
}
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);
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);
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.
}
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
}
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.
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 isnull.includeUnverified-- Whether unverified breaches should be included. Default isfalse.
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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jgxvx/cilician 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provide a way to secure accesses to all routes of an symfony application.
A PSR-7 compatible library for making CRUD API endpoints
It's a barebone security class written on PHP
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
Contao CMS integrity check for some files
统计信息
- 总下载量: 9.77k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 9
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-09-29