inventas/laravel-password-compliance
Composer 安装命令:
composer require inventas/laravel-password-compliance
包简介
Enforce password change for next login in a Laravel app.
README 文档
README
Enforce forced password resets in your Laravel application.
This package lets you mark users as requiring a password change and redirect them to a dedicated change-password page using a middleware. It provides a small programmatic API, a convenient trait for your Authenticatable model, and a middleware alias you can attach to routes.
Installation
You can install the package via composer:
composer require inventas/laravel-password-compliance
You can publish and run the migrations with:
php artisan vendor:publish --tag="password-compliance-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="password-compliance-config"
This is the contents of the published config file:
return [
];
Optionally, you can publish the views using
php artisan vendor:publish --tag="password-compliance-views"
Overview
- Programmatic API to require a user to change their password.
- Middleware alias
password.compliancewhich redirects users that must change their password to a configured route or URL. - A trait
RequiresPasswordChangeyou can add to your Authenticatable model for convenience methods and relationship access.
Configuration
The published config file is config/password-compliance.php and contains a few options:
redirect_route— optional route name to redirect users to (recommended)redirect_url— fallback URL whenredirect_routeis not setexempt_routes— an array of route names which should be exempt from the middleware (useful for the change-password route itself)guard— optional guard name to check for the authenticated user
Example (config/password-compliance.php):
return [ 'redirect_route' => 'password.change', 'redirect_url' => '/password/change', 'exempt_routes' => ['password.change'], 'guard' => null, ];
Usage
Trait
Add the trait to your User model:
use Inventas\PasswordCompliance\Traits\RequiresPasswordChange; class User extends Authenticatable { use RequiresPasswordChange; }
This trait provides these convenience methods:
$user->requirePasswordChange($until = null, $reason = null)— mark the user as required to change their password until an optional time (passnullfor indefinite).$user->clearPasswordRequirement()— clear the requirement for the user.$user->isPasswordChangeRequired()— check whether the user currently must change their password.$user->passwordCompliance()— amorphOnerelation to the underlying database record.
Programmatic API / Facade
The package exposes a small service and a facade. Use the facade if you prefer a static-looking interface:
use Inventas\PasswordCompliance\Facades\PasswordCompliance; // require indefinitely PasswordCompliance::requirePasswordChange($user, null, 'Admin forced reset'); // require until a date PasswordCompliance::requirePasswordChange($user, now()->addDays(7)); // clear PasswordCompliance::clearRequirement($user);
Middleware
The middleware alias password.compliance is registered by the package. Attach it to routes or route groups to ensure users who are required to change their password are redirected:
Route::middleware(['auth', 'password.compliance'])->group(function () { // protected routes });
The middleware will:
- skip unauthenticated requests
- skip API/JSON requests by default (so APIs won't receive HTML redirects)
- skip routes listed in
exempt_routesin the config - redirect to the named route in
redirect_routeor toredirect_urlif the route is not set
Testing
The package includes Pest tests. Run them with:
vendor/bin/pest
Contributing
Contributions are very welcome. Please open issues or PRs. If you add functionality, include tests (Pest) and keep backwards compatibility where possible.
License
The package is open-sourced software licensed under the MIT license.
inventas/laravel-password-compliance 适用场景与选型建议
inventas/laravel-password-compliance 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 114 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「Inventas」 「laravel-password-compliance」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 inventas/laravel-password-compliance 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 inventas/laravel-password-compliance 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 inventas/laravel-password-compliance 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel SDK for the Apple Maps Server API
Alfabank REST API integration
Expose Laravel authorization abilities on the frontend for Laravel Data resources.
Save website support cases and send them to team
Laravel package for Accurate Online API integration.
Shared RCX Laravel DataTables UI and configuration helpers.
统计信息
- 总下载量: 114
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-26