olssonm/l5-zxcvbn
Composer 安装命令:
composer require olssonm/l5-zxcvbn
包简介
Implementation of the zxcvbn project by @dropbox for Laravel. Uses zxcvbn-php by @bjeavons.
README 文档
README
A simple implementation of zxcvbn for Laravel. This package allows you to access "zxcvbn-related" data on a passphrase in the application and also to use zxcvbn as a standard validator.
Uses Zxcvbn-PHP by @bjeavons, which in turn is inspired by zxcvbn by @dropbox.
Install
Via Composer
$ composer require olssonm/l5-zxcvbn
If you wish to have the ability to use Zxcvbn via dependency injection, or just have a quick way to access the class – add an alias to the facades:
'aliases' => [ 'Zxcvbn' => Olssonm\Zxcvbn\Facades\Zxcvbn::class ]
Usage
If you've added Olssonm\Zxcvbn as an alias, your can access Zxcvbn easily from anywhere in your application:
"In app"
use Zxcvbn; class MyClass extends MyOtherClass { public function myFunction() { $zxcvbn = Zxcvbn::passwordStrength('password'); dd($zxcvbn); // array:9 [ // "password" => "password" // "guesses" => 3.0 // "guesses_log10" => 0.47712125471966 // "sequence" => [], // "crack_times_seconds" => array:4 [ // "online_throttling_100_per_hour" => 108.0 // "online_no_throttling_10_per_second" => 0.3 // "offline_slow_hashing_1e4_per_second" => 0.0003 // "offline_fast_hashing_1e10_per_second" => 3.0E-10 // ] // "crack_times_display" => array:4 [ // "online_throttling_100_per_hour" => "2 minutes" // "online_no_throttling_10_per_second" => "less than a second" // "offline_slow_hashing_1e4_per_second" => "less than a second" // "offline_fast_hashing_1e10_per_second" => "less than a second" // ] // "score" => 0 // "feedback" => array:2 [ // "warning" => "This is a top-10 common password" // "suggestions" => array:1 [ // 0 => "Add another word or two. Uncommon words are better." // ] // ] // "calc_time" => 0.020488977432251 // ] } }
Play around with different passwords and phrases, the results may surprise you. Check out Zxcvbn-PHP for more uses and examples.
As a validator
The package makes two types of validations available for your application. zxcvbn and zxcvbn_dictionary.
zxcvbn
With this rule you set the lowest score that the phrase need to score wuth Zxcvbn to pass.
Syntax
'input' => 'zxcvbn:min_value'
Examples
$request->validate([ 'password' => 'required|zxcvbn:3' ]);
You may also initialize the rule as an object:
use Olssonm\Zxcvbn\Rules\Zxcvbn; function rules() { return [ 'password' => ['required', new Zxcvbn($minScore = 3)] ]; }
In this example the password should at least have a "score" of three (3) to pass the validation. Of course, you should probably use the zxcvbn-library on the front-end too to allow the user to know this before posting the form.
zxcvbn_dictionary
This is a bit more interesting. zxcvbn_dictionary allows you to input both the users username and/or email together with their password (you need suply one piece of user input). The validator checks that the password doesn't exist in the username, or that they are too similar.
Syntax
'input' => 'zxcvbn_dictionary:input1,input2'
Examples
$request->validate([ 'password' => sprintf('required|zxcvbn_dictionary:%s,%s', $request->username, $request->email) ]);
use Olssonm\Zxcvbn\Rules\ZxcvbnDictionary; function rules() { return [ 'password' => ['required', new ZxcvbnDictionary($this->username)] ]; }
Testing
$ composer test
or
$ phpunit
License
The MIT License (MIT). Please see the License File for more information.
© 2022 Marcus Olsson.
olssonm/l5-zxcvbn 适用场景与选型建议
olssonm/l5-zxcvbn 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 330.46k 次下载、GitHub Stars 达 29, 最近一次更新时间为 2015 年 10 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「validation」 「laravel」 「passwords」 「zxcvbn」 「olssonm」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 olssonm/l5-zxcvbn 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 olssonm/l5-zxcvbn 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 olssonm/l5-zxcvbn 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provide a way to secure accesses to all routes of an symfony application.
It's a barebone security class written on PHP
Adds request-parameter validation to the SLIM 3.x PHP framework
A jQuery augmented PHP library for creating and validating HTML forms
Contao CMS integrity check for some files
A Laravel validator for delimiter-separated list of emails.
统计信息
- 总下载量: 330.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 29
- 点击次数: 35
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-16
