mxrxdxn/pwned-passwords

这是一个查询Troy Hunt的Pwned Passwords服务的库,用于查看密码是否被包含在公开的安全漏洞中。

v2.1.0 2021-08-24 18:26 UTC

This package is auto-updated.

Last update: 2024-09-20 22:53:29 UTC


README

这是一个查询Troy Hunt的Pwned Passwords服务的库,用于查看密码是否被包含在公开的安全漏洞中。

要求

  • PHP >= 7.2

安装

通过Composer安装PwnedPasswords非常简单。只需使用以下命令要求该包,您就可以开始使用了。

composer require mxrxdxn/pwned-passwords

用法

要使用这个库,你可以按照以下示例进行。

require_once('vendor/autoload.php');

$pp = new PwnedPasswords\PwnedPasswords;

$password = '123456789';

$insecure = $pp->isPwned($password); //returns true or false

isInsecure方法将在密码在PwnedPasswords API中被找到时返回true,否则返回false。

如果你想要建立自己的阈值(例如,如果密码被找到超过一次,则显示警告;如果超过5次,则显示错误),你可以像下面这样调用isPwned方法。

$pp = new PwnedPasswords\PwnedPasswords;

$password = '123456789';

$insecure = $pp->isPwned($password, true);

if ($insecure) {
    echo 'Oh no — pwned!' . "\n";
    echo sprintf('This password has been seen %d time%s before.', $insecure, ($insecure > 1 ? 's' : ''));
} else {
    echo 'All good!';
}

问题

请随时使用GitHub问题跟踪器来发布你在这个库中遇到的问题。