acurrieclark/php-password-verifier

框架无关的密码强度检查器

v1.1 2021-01-18 15:42 UTC

This package is auto-updated.

Last update: 2024-08-27 23:24:54 UTC


README

PHP 的框架无关密码检查器。

安装

$ composer require acurrieclark/php-password-verifier

用法

// include autoloader if you haven't already
include_once('vendor/autoload.php');

use acurrieclark\PhpPasswordVerifier\Verifier;

// create an instance
$passwordVerifier = new Verifier();

// default options are permissive, so  each constraint needs to be set as required
$passwordVerifier->setMinLength(8);

// constraints can also be chained
$passwordVerifier->setMaxLength(128)->setCheckContainsNumbers(true);

// check the password meets the requirements set (min length 8, max length 128, contains numbers)

$validPassword = $passwordVerifier->checkPassword("passwordToCheck");

类方法

设置密码约束

setMinLength(int $length)

设置密码所需的最小长度

setMaxLength(int $length)

设置密码允许的最大长度

setCheckContainsLetters(boolean $value)

设置标志以检查密码是否至少包含一个字母

setCheckContainsCapitals(boolean $value)

设置标志以检查密码是否至少包含一个大写字母

setCheckContainsNumbers(boolean $value)

设置标志以检查密码是否至少包含一个数字

setCheckContainsNumbers(boolean $value)

设置标志以检查密码是否至少包含一个数字

setCheckContainsSpecialChrs(boolean $value)

设置标志以检查密码是否至少包含一个特殊字符,从 {}()[]#,:;^.?!|&_`~@$%/\\=+-*"' 中选择

setCheckBlacklist(boolean $value)

设置标志以检查密码是否与来自 https://github.com/danielmiessler/SecLists 的 10,000 个最常见密码之一匹配

检查密码

checkPassword(string $password)

根据施加的约束验证密码。返回布尔值。

getErrors()

返回与验证的密码相关的错误数组

实用工具

getSpecialChrs()

静态: 返回用于与 setCheckContainsSpecialChrs(true) 设置检查时进行比较的特殊字符数组。如果你想要警告用户他们需要包含哪些字符,这很有用。

许可

MIT 许可证(MIT)。请参阅许可文件获取更多信息。