moritzdemmer / enzoic
Enzoic API 的 PHP 库
dev-master
2021-10-01 11:06 UTC
Requires
- php: >=5.5
- ext-curl: *
Requires (Dev)
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-09-29 06:03:12 UTC
README
目录
本 README 涵盖以下主题
安装
使用 Composer 将 Enzoic 库包含到您的项目中
$ composer require enzoic/enzoic
Enzoic for PHP 需要安装并可通过您的 PHP 应用程序运行 Argon2 命令行工具。有关安装说明,请参阅 https://github.com/P-H-C/phc-winner-argon2。
API 概览
以下是一些简单的示例代码,展示了如何使用 API。
<?php use Enzoic\Enzoic; use Enzoic\PasswordType; // Create a new Enzoic instance - this is our primary interface for making API calls $enzoic = new Enzoic(YOUR_API_KEY, YOUR_API_SECRET); // Check whether a password has been compromised $passwordCompromised = $enzoic->checkPassword('password-to-test'); if ($passwordCompromised === true) { echo 'Password is compromised'; } else { echo 'Password is not compromised'; } // Check whether a specific set of credentials are compromised $credentialsCompromised = $enzoic->checkCredentials('test@enzoic.com', 'password-to-test'); if ($credentialsCompromised === true) { echo 'Credentials are compromised'; } else { echo 'Credentials are not compromised'; } // checkCredentials has optional parameters offering more control over performance. // // lastCheckDate: // A DateTime containing the timestamp of the last credentials check you performed for this user. // If the date/time you provide for the last check is greater than the timestamp Enzoic has for the last // breach affecting this user, the check will not be performed. This can be used to substantially increase performance // after the initial call. // // excludeHashAlgorithms: // An array of PasswordTypes to ignore when calculating hashes for the credentials check. // By excluding computationally expensive PasswordTypes, such as BCrypt, it is possible to balance the performance of this // call against security. // // should be set to the last time you checked credentials for this user for performance $dateOfLastCredentialsCheck = new DateTime('2020-07-01T02:05:03.000Z'); // let's exclude BCrypt and PHPBB3 $excludeHashAlgorithms = [ PasswordType::BCrypt, PasswordType::PHPBB3 ]; $credentialsCompromised = $enzoic->checkCredentials('test@enzoic.com', 'password-to-test', $dateOfLastCredentialsCheck, $excludeHashAlgorithms); if ($credentialsCompromised === true) { echo 'Credentials are compromised'; } else { echo 'Credentials are not compromised'; } // get all exposures for the given user $userExposures = $enzoic->getExposuresForUser('eicar_1@enzoic.com'); echo count($userExposures).' exposures found for eicar_1@enzoic.com'; // now get the full details for the first exposure returned in the list $exposureDetails = $enzoic->getExposureDetails($userExposures[0]); echo 'First exposure for test@enzoic.com was '.$exposureDetails->{'title'}; ?>
以下是一些关于参考格式的更多信息。
Enzoic 构造函数
标准构造函数接受在 Enzoic 注册时分配给您的 API 密钥和密钥。
$enzoic = new Enzoic(YOUR_API_KEY, YOUR_API_SECRET);
如果您被要求使用替代 API 主机,您可以调用重载的构造函数并传递您提供的宿主。
$enzoic = new Enzoic(YOUR_API_KEY, YOUR_API_SECRET, "api-alt.enzoic.com");