fadonougbo/password-policy
Composer 安装命令:
composer require fadonougbo/password-policy
包简介
Password validation Library
关键字:
README 文档
README
PasswordPolicy is a library that allows defining various validation rules for passwords.
Installation
composer require fadonougbo/password-policy
Usage
Create a new instance of PasswordPolicy
use PasswordPolicy\PasswordPolicy; $policy=new PasswordPolicy('paswword');
Now add rule
use PasswordPolicy\PasswordPolicy; $status=(new PasswordPolicy('password')) ->withLowercase() // [a-z] ->withUppercase() // [A-Z] ->withNumber() // [0-9] ->withSymbol() // [\W_] ->getStatus(); var_dump($status);
true
The methods withLowercase, withUppercase, withSymbol, and withNumber can take a minimum or maximum value as a parameter, representing the accepted number of occurrences.
use PasswordPolicy\PasswordPolicy; $password=$_POST['password']; $status=(new PasswordPolicy($password)) ->withLowercase(2) // minimum 2 lowercase letters ->withUppercase(2,3) // 2 to 3 uppercase letters ->withNumber(max:1) // 0 or 1 number ->withSymbol(1,1) // 1 symbol ->getStatus(); if($status) { echo 'Very good'; }else { echo 'error'; }
| password | validated |
|---|---|
| useR@aMin0 | true |
| sJw*Bc | true |
| 2002doe | false |
You can use the getData method to get much more information.
use PasswordPolicy\PasswordPolicy; $data=(new PasswordPolicy('%USERmsjah22')) ->withLowercase() // 0 or more lowercase letters ->withUppercase(4) // minimum 4 uppsercase letters ->withSymbol(max:3) // 0 to 3 symbol ->getData(); echo $data->password; echo $data->status; echo $data->length;
%USERmsjah22
true
12
Attention, if you want the complete absence of numbers in the password, you must specify it in the withNumber method. The same goes for lowercase letters, uppercase letters, and symbols.
use PasswordPolicy\PasswordPolicy; $password=$_POST['password']; $status=(new PasswordPolicy($password)) ->withLowercase(0,0) // 0 lowercase letter ->withUppercase(0,0) // 0 uppercase letter ->withNumber() // 0 or more numbers ->getStatus();
| password | validated |
|---|---|
| 2003# | true |
| 9093761 | true |
| eiwWS39 | false |
| PASSWORD | false |
| #*@(#& | true |
The blockSameCharacters method invalidates the password if it contains repeated characters a certain number of times.
e.g: aaaaaa ,bbbbb ,password11111
use PasswordPolicy\PasswordPolicy; $data=(new PasswordPolicy('user222222')) ->blockSameCharacter(4) //Does not accept passwords with a repeated character 4 or more times. ->getData(); echo $data->status;
false
If you want to block a user who uses a previous password, you can use the blockIf method
use PasswordPolicy\PasswordPolicy; $oldPasswordHash='$2y$10$i8FPWdu/4B.GV4Cl8Hq80.9p/TjrGncCrhkQYjradFpy6o/CAJnsG'; $status=(new PasswordPolicy('newpassword')) ->blockIf(function($password) use($oldPasswordHash) { return !password_verify($password,$oldPasswordHash); }) ->getStatus(); if($status) { echo 'Yes, it is ok'; }else { echo 'You cannot use an old password.'; }
You can use blockCommonPasswords to block some of the most commonly used passwords in the world, such as azerty or 12345.
use PasswordPolicy\PasswordPolicy; $response=(new PasswordPolicy('iloveyou')) ->blockCommonPasswords("This password is too weak") ->getData(); if($response->status) { echo 'Yes, it is ok'; }else { echo $response->messages['blockCommonPasswords']; }
This password is too weak
NB: If you need to define a list of undesirable passwords, you can use blockListContent.
Define the size of a password withsetLength
use PasswordPolicy\PasswordPolicy; $response=(new PasswordPolicy('JohnD0e2oo2')) ->setLength(6) // min 6 characters ->getData();
fadonougbo/password-policy 适用场景与选型建议
fadonougbo/password-policy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 03 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「validation」 「password」 「Policy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fadonougbo/password-policy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fadonougbo/password-policy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fadonougbo/password-policy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple and configurable SilverStripe module to notify users about cookie policies
A module for CSP headers in Silverstripe.
The PHP class PasswordGenerator serves as a password generator to create memorable passwords like the keychain of macOS ≤ 10.14 did.
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
High-level cryptographic primitives and security utilities for Maatify systems including password hashing, reversible encryption, HKDF key derivation, and key rotation.
A library for reading KeePass 2.x databases
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-27