code-pros/password-policy

创建密码策略并验证字符串是否符合该策略

1.0.0 2021-06-18 14:13 UTC

This package is auto-updated.

Last update: 2024-09-18 21:15:00 UTC


README

创建密码策略并对密码进行验证。

当用户创建/更新密码时很有用。

安装

使用Composer管理您的依赖项

composer require code-pros/password-policy

示例

/**
 * Setup a password policy
 * This policy is from OWASP's security cheat sheet.  Look it up for good reading!
 *
 * Must match 3/4 of the following
 * - Lowercase character
 * - Uppercase character
 * - Special character
 * - Digit
 * Must match all of the following
 * - between 10 and 128 characters
 * - no consecutive characters more than twice
 */
$childPolicy = \CodePros\PasswordPolicy\Builder::create()
        ->addMustRule(new \CodePros\PasswordPolicy\Rules\Characters\Lowercase(1))
        ->addMustRule(new \CodePros\PasswordPolicy\Rules\Characters\Uppercase(1))
        ->addMustRule(new \CodePros\PasswordPolicy\Rules\Characters\Digit(1))
        ->addMustRule(new \CodePros\PasswordPolicy\Rules\Characters\Special(1))
        ->pctRulesMustPass(75)
        ->build();

$policy = \CodePros\PasswordPolicy\Builder::create()
        ->addMustRule(new \CodePros\PasswordPolicy\Rules\Characters\Length(10, 128))
        ->addMustNotRule(new \CodePros\PasswordPolicy\Rules\ConsecutiveCharacters(3))
        ->mustPassPolicy($childPolicy)
        ->build();

/**
 * Validate a password
 */
$valid = $policy->validate('user supplied password');

/**
 * Get back a list of rules and whether the last validation passed each.
 */
$messages = $policy->getDetailedStatus();

开发

开发流程

  1. 进行更改。
  2. 使用PHPUnit进行测试。

构建流程

  1. 根据semver选择新的版本号。
  2. 在带有新版本号的CHANGELOG中总结您的更改。
  3. 使用版本号创建git标签。
  4. 推送更改和标签。