承接 tigron/password-strength 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tigron/password-strength

Composer 安装命令:

composer require tigron/password-strength

包简介

Validates a given password for its strength

README 文档

README

This library can calculate the strength of the password based on a given password ruleset.

Installation

composer require tigron/password-strength

Define a ruleset

In order to calculate a password strength, you must first define a ruleset. A ruleset is a list of rules which you would like to implement for your application.

$ruleset = new \Password\Ruleset();

// Matches any password. Sets a base score of 'INSECURE'.
$rule = new \Password\Rule();
$rule->add_condition(new Condition\Length\Min(0));
$rule->set_strength(\Password\Strength::VULNERABLE);
$ruleset->add_rule($rule);

// More complex passwords can receive a higher score
$rule = new \Password\Rule();
$rule->add_condition(new Condition\Length\Min(5));
$rule->set_strength(\Password\Strength::INSECURE);
$ruleset->add_rule($rule);

$rule = new \Password\Rule();
$rule->add_condition(new Condition\Length\Min(5));
$rule->add_condition(new Condition\Lowercase(true));
$rule->add_condition(new Condition\Uppercase(true));
$rule->set_strength(\Password\Strength::ACCEPTABLE);
$ruleset->add_rule($rule);

Test a password

In order to test the password against the defined ruleset, use the following code

$ruleset->set_password($password);
$strength = $ruleset->get_strength();

Strengths

This library implements 5 levels of strength, all expressed as a score from 0 to 5.

\Password\Strength::NONE		// Score 0
\Password\Strength::VULNERABLE		// Score 1
\Password\Strength::INSECURE		// Score 2
\Password\Strength::ACCEPTABLE		// Score 3
\Password\Strength::GOOD		// Score 4
\Password\Strength::STRONG		// Score 5

If the password did not match any rule, it will receive score 0. This indicates that a wider base rule needs to be implemented.

Conditions

The following conditions are implemented and can be used in any rule.

/**
 * Put a condition on the presence of an uppercase letter in the password
 */
new \Password\Condition\Uppercase(bool $requested_value)

/**
 * Put a condition on the presence of an lowercase letter in the password
 */
new \Password\Condition\Lowercase(bool $requested_value)

/**
 * Put a condition on the presence of a number
 */
new \Password\Condition\Number(bool $requested_value)

/**
 * Put a condition on the presence of a symbol
 */
new \Password\Condition\Symbol(bool $requested_value)

/**
 * Put a condition on minimum length of the password
 */
new \Password\Condition\Length\Min(int $length)

/**
 * Put a condition on maximum length of the password
 */
new \Password\Condition\Length\Max(int $length)

/**
 * Put a condition on the amount of occurences in haveibeenpwned.com
 */
new \Password\Condition\Pwned(?int $occurences)

/**
 * Put a condition on the score of Zxcvbn
 * https://lowe.github.io/tryzxcvbn/
 */
new \Password\Condition\Zxcvbn(int $score)

/**
 * Put a condition on the score of the entropy calculation
 * https://gitlab.com/garybell/password-validation/
 */
new \Password\Condition\Entropy(int $score)

Preset

This library has built-in presets of rules that you can include in your project

/**
 * Hive 2024 password table
 * https://www.hivesystems.com/blog/are-your-passwords-in-the-green
 */
$ruleset->import_rules(\Password\Preset\Hive2024::export());

/**
 * Zxcvbn password strength estimator using pattern matching and
 * minimum entropy calculation
 * https://github.com/bjeavons/zxcvbn-php/tree/master
 */
$ruleset->import_rules(\Password\Preset\Zxcvbn::export());

/**
 * entropy password strength calculator
 * https://gitlab.com/garybell/password-validation
 */
$ruleset->import_rules(\Password\Preset\Entropy::export());

/**
 * Tigron company policy rule. It includes:
 * - Hive 2024
 * - Zxcvbn
 * - entropy
 */
$ruleset->import_rules(\Password\Preset\Tigron::export());

统计信息

  • 总下载量: 1.93k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固