sicaboy/laravel-security
Composer 安装命令:
composer require sicaboy/laravel-security
包简介
This package can be used to enhance the user security of Laravel projects.
关键字:
README 文档
README
Introduction
This package can be used to enhance the user security of Laravel projects.
Installation
Requirements:
To get the latest version of Laravel Security, simply run:
composer require sicaboy/laravel-security
Then do vendor publish:
php artisan vendor:publish --provider="Sicaboy\LaravelSecurity\LaravelSecurityServiceProvider"
After publishing, you can modify templates and config in:
app/config/laravel-security.php
resources/views/vendor/laravel-security/
resources/lang/en/laravel-security.php
If you're on Laravel < 5.5, you'll need to register the service provider. Open up config/app.php and add the following to the providers array:
Siaboy\LaravelSecurity\LaravelSecurityServiceProvider::class,
Features
Disallow user to use a common password or a used password
Verify the user-provided password is not one of the top 10,000 worst passwords as analyzed by a respectable IT security analyst. Read about all here, here(wired) or here(telegram)
Available validators rules
-
NotCommonPassword - Avoid user to use a common used password
-
NotAUsedPassword - Avoid user to use a password which has been used before
// Add rule instance to the field validation rules list public function rules() { return [ 'password_field' => [ 'required', 'confirmed', 'min:8', 'regex:/[a-z]/', // must contain at least one lowercase letter 'regex:/[A-Z]/', // must contain at least one uppercase letter 'regex:/[0-9]/', // must contain at least one digit //... new \Sicaboy\LaravelSecurity\Rules\NotCommonPassword(), new \Sicaboy\LaravelSecurity\Rules\NotAUsedPassword($user), ], ]; } // Also you need to call event, examples in the next section
CAUTION: Extra event you need to call
User login and register events have been automatically traced. While there is an extra event you should add to call explicitly.
// Call on user password change event(new \Illuminate\Auth\Events\PasswordReset($user)); // If you are using custom login, register and reset password actions which are not the Laravel built-in ones, you will need to call event in your function accordingly. event(new \Illuminate\Auth\Events\Login($user)); event(new \Illuminate\Auth\Events\Registered($user)); event(new \Illuminate\Auth\Events\PasswordReset($user));
Usage
Password Policies
- Delete accounts with days of no activity
- Lockout accounts with days of no activity
- Force change password every x days
- To enable the first two policies, you need to set
enabledtotrueinconfig/laravel-security.phpas below:
... 'password_policy' => [ // Delete accounts with days of no activity 'auto_delete_inactive_accounts' => [ 'enabled' => true, ... ], // Lock out accounts with days of no activity 'auto_lockout_inactive_accounts' => [ 'enabled' => true, ... ], ] ...
- To reject locked accounts and force user to change their password every x days, you will need to use this middleware
Route::middleware(['security'])->group(function () { ... });
If Using Different User Objects
- If you use different
Userobjects, for example a traditionalApp\Userand a customize admin user, you can write middleware this way:
Route::middleware(['security:admin'])->group(function () { ... });
- Add config group in your
config/laravel-security.php
return [ 'default' => [ ... ], 'group' 'admin' => [ // Example, when using middleware 'security:admin'. Attributes not mentioned will be inherit from `default` above ... ], 'other_name' => [ // Middleware 'security:other_name' ... ] ],
- To enable
Force change password every x daysyou need to setenabledtotrueandchange_password_urlinconfig/laravel-security.phpas below:
... 'password_policy' => [ ... // Force change password every x days 'force_change_password' => [ 'enabled' => true, 'days_after_last_change' => 90, // every 90 days 'change_password_url' => '/user/change-password', // Change My Password page URL ], ... ] ...
- Add the following commands to
app/Console/Kernel.phpof your application. Implement to one instance if using web server clusters
protected function schedule(Schedule $schedule) { $schedule->command(\Sicaboy\LaravelSecurity\Console\Commands\DeleteInactiveAccounts::class) ->hourly(); $schedule->command(\Sicaboy\LaravelSecurity\Console\Commands\LockoutInactiveAccounts::class) ->hourly(); ... }
- Make sure you add the Laravel scheduler in your crontab Implement to one instance if using web server clusters
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
Multi-factor Authentication
This feature has been moved to sicaboy/laravel-mfa
TODO
-
Ability to split
extended_securitytable to multiple tables. or other methods to support websites with huge user mount. -
Add cron job to remove too old password records to avoid heavy table.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.
License
The MIT License (MIT). Please see License File for more information.
sicaboy/laravel-security 适用场景与选型建议
sicaboy/laravel-security 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 107 次下载、GitHub Stars 达 7, 最近一次更新时间为 2020 年 04 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「laravel」 「passwords」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sicaboy/laravel-security 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sicaboy/laravel-security 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sicaboy/laravel-security 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Password Validator validates password_hash generated passwords, rehashes passwords as necessary, and will upgrade legacy passwords.
Simple class for passwords hashing and checking using Blowfish algorithm
PHP Client for haveibeenpwned.com APIs
Provide a way to secure accesses to all routes of an symfony application.
Re-hash passwords from an old platform on the fly
It's a barebone security class written on PHP
统计信息
- 总下载量: 107
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-12