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

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

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

philiprehberger/php-password-strength

Composer 安装命令:

composer require philiprehberger/php-password-strength

包简介

Password strength validation with entropy calculation and common password detection

README 文档

README

Tests Latest Version on Packagist Last updated

Password strength validation with entropy calculation and common password detection.

Requirements

  • PHP 8.2+

Installation

composer require philiprehberger/php-password-strength

Usage

Checking password strength

use PhilipRehberger\PasswordStrength\PasswordStrength;

$result = PasswordStrength::check('MyP@ssw0rd!2026');

echo $result->score;       // 0-4
echo $result->label();     // "very weak", "weak", "fair", "strong", or "very strong"
echo $result->entropy;     // Shannon entropy in bits
echo $result->isCommon;    // true if found in common passwords list
echo $result->length;      // Password length

// Improvement suggestions
foreach ($result->suggestions as $suggestion) {
    echo $suggestion;
}

// Array representation
$array = $result->toArray();

Quick validation

use PhilipRehberger\PasswordStrength\PasswordStrength;

// Returns true if score >= 3 (strong)
if (PasswordStrength::isStrong('MyP@ssw0rd!2026')) {
    echo 'Password is strong enough.';
}

// Custom minimum score
if (PasswordStrength::isStrong('MyP@ssw0rd!2026', minScore: 4)) {
    echo 'Password is very strong.';
}

Detailed analysis

use PhilipRehberger\PasswordStrength\PasswordStrength;

$report = PasswordStrength::analyze('MyP@ssw0rd!2026');

echo $report->score;             // 0-4
echo $report->level;             // "very weak", "weak", "fair", "strong", or "very strong"
echo $report->length;            // Password length
echo $report->hasLowercase;      // true
echo $report->hasUppercase;      // true
echo $report->hasDigits;         // true
echo $report->hasSymbols;        // true
echo $report->hasRepeatedChars;  // false
echo $report->hasSequentialChars; // false
echo $report->hasKeyboardPattern; // false

Custom dictionary

use PhilipRehberger\PasswordStrength\PasswordStrength;

PasswordStrength::addDictionary(['company', 'acme', 'internal']);

$result = PasswordStrength::check('acmepassword');
// Score reduced, suggestion: "Avoid dictionary words."

PasswordStrength::clearDictionaries();

Personal context checking

use PhilipRehberger\PasswordStrength\PasswordStrength;

$report = PasswordStrength::withContext(['john', 'john@example.com'])
    ->analyze('john2024!');

echo $report->hasPersonalContext; // true
// Suggestion: "Avoid using personal information in your password"

Policy-based validation

use PhilipRehberger\PasswordStrength\PasswordPolicy;
use PhilipRehberger\PasswordStrength\PasswordStrength;

$policy = (new PasswordPolicy)
    ->minLength(10)
    ->requireUppercase()
    ->requireDigits()
    ->requireSymbols()
    ->minScore(3);

// Using the policy directly
$policy->check('MyP@ssw0rd!2026'); // true

// Using the main class
PasswordStrength::meetsPolicy('MyP@ssw0rd!2026', $policy); // true
PasswordStrength::meetsPolicy('weak', $policy);             // false

API

PasswordStrength

Method Description
PasswordStrength::check(string $password): StrengthResult Analyse a password and return a result
PasswordStrength::isStrong(string $password, int $minScore = 3): bool Returns true if the score meets the minimum
PasswordStrength::analyze(string $password): StrengthReport Return a detailed strength report with analysis flags
PasswordStrength::meetsPolicy(string $password, PasswordPolicy $policy): bool Check if a password satisfies a policy
PasswordStrength::addDictionary(array $words): void Add custom dictionary words to check against
PasswordStrength::clearDictionaries(): void Clear all custom dictionaries
PasswordStrength::withContext(array $context): PendingAnalysis Create a pending analysis with personal context

StrengthResult

Property / Method Type Description
score int Strength score from 0 to 4
entropy float Shannon entropy in bits
isCommon bool Whether the password is in the common list
length int Password length in characters
suggestions array List of improvement suggestions
label(): string Human label: very weak, weak, fair, strong, very strong
toArray(): array Serialize to array

StrengthReport

Property Type Description
score int Strength score from 0 to 4
level string Human-readable strength level
hasLowercase bool Whether the password contains lowercase letters
hasUppercase bool Whether the password contains uppercase letters
hasDigits bool Whether the password contains digits
hasSymbols bool Whether the password contains special characters
hasRepeatedChars bool Whether the password has 3+ repeated characters in a row
hasSequentialChars bool Whether the password has 3+ sequential characters
hasKeyboardPattern bool Whether the password contains keyboard patterns
length int Password length in characters
hasPersonalContext bool Whether the password contains personal context information
suggestions array List of improvement suggestions

PendingAnalysis

Method Description
analyze(string $password): StrengthReport Analyze a password with personal context applied

PasswordPolicy

Method Description
minLength(int $length): self Set minimum password length
requireUppercase(): self Require at least one uppercase letter
requireDigits(): self Require at least one digit
requireSymbols(): self Require at least one special character
minScore(int $score): self Set minimum strength score (0-4)
check(string $password): bool Check if a password meets the policy

Score Meanings

Score Label Description
0 Very Weak Trivial or common password
1 Weak Low entropy or very short
2 Fair Moderate entropy, room to improve
3 Strong Good entropy and character variety
4 Very Strong Excellent entropy and length

Development

composer install
vendor/bin/phpunit
vendor/bin/pint --test

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT

philiprehberger/php-password-strength 适用场景与选型建议

philiprehberger/php-password-strength 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 58 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 03 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「security」 「validation」 「password」 「strength」 「entropy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 philiprehberger/php-password-strength 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 philiprehberger/php-password-strength 我们能提供哪些服务?
定制开发 / 二次开发

基于 philiprehberger/php-password-strength 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-13