八十九 / 线材密码过期
允许用户定期重置密码,以加强安全性。
3.0.2
2024-09-13 14:33 UTC
Requires
- php: ^8.1
- filament/filament: ^3.0
- spatie/laravel-package-tools: ^1.15.0
Requires (Dev)
- nunomaduro/collision: ^7.9
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.1
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
README
🛠️ 加入我们的旅程
嗨,我是八十九。我创建了密码过期插件来解决我作为开发者遇到的真实问题。您的赞助将使我能够投入更多时间来改进这些工具并帮助更多的人。 成为赞助者 并与我一起在开发者社区中产生积极影响。
允许用户定期重置密码,以加强安全性。
此包允许您定期重置用户的密码,以加强安全性。在您的系统中,您必须强制用户每30-90天更改一次密码。这确保了即使用户不再使用系统,其他人也无法使用旧密码登录。
安装
您可以通过composer安装此包
composer require eightynine/filament-password-expiry
将插件添加到您的面板
- 在您面板的提供者中,将插件添加为
use EightyNine\FilamentPasswordExpiry\PasswordExpiryPlugin; public function panel(Panel $panel): Panel { return $panel ... ->plugin(PasswordExpiryPlugin::make()); }
- 发布迁移和配置文件,以便设置密码过期表和列。
php artisan vendor:publish --tag="password-expiry-migrations" php artisan vendor:publish --tag="password-expiry-config" php artisan migrate
如果您需要,可以使用以下命令发布翻译文件
php artisan vendor:publish --tag="password-expiry-translations"
- 在您的认证类中,例如
app/Models/User.php
,将密码过期特性添加到模型中,该特性检查所有设置是否正确,如果不正确则抛出异常。特性将在用户创建时更新 password_expires_at 列。
use EightyNine\FilamentPasswordExpiry\Concerns\HasPasswordExpiry; class User extends Authenticatable { use HasPasswordExpiry; ... }
- 此插件在创建新密码时不会散列密码。相反,请确保您的 User 模型中将密码转换为 'hashed'。
/** * Get the attributes that should be cast. * * @return array<string, string> */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; }
现在您已经准备就绪!当用户被创建时,password_expires_at 列将更新为当前日期和时间加上 expires_in 配置值。当用户尝试登录时,中间件将检查 password_expires_at 列是否小于当前日期和时间。如果是,则用户将被重定向到密码过期页面。
这是已发布的配置文件内容
return [ /** * Table * * The table to store the password expiry data in. */ 'table_name' => 'users', /** * Column * * The column to store the password expiry data in. */ 'column_name' => 'password_expires_at', /** * Password column name * * The name of the password column, will be updated when setting the new password. */ 'password_column_name' => 'password', /** * Expiry * * The number of days before the password expires. */ 'expires_in' => 30, /** * Password expiry route * * The route to redirect to when the password expires. */ 'password_expiry_route' => 'password-expiry.reset-password', /** * Password expiry path * * The path to redirect to when the password expires. */ 'password_expiry_path' => 'password-expiry/reset-password', /** * Password expiry middleware * * The middleware to use for password expiry. */ 'password_expiry_middleware' => PasswordExpiryMiddleware::class, /** * Password expiry middleware * * The middleware to use for password expiry. */ 'password_reset_page' => ResetPassword::class, /** * Auth class * * The auth class to use for password expiry. By default, the package uses Filament::auth()->user(). Make sure the auth class * also contains the column defined in the table_name config. */ 'auth_class' => Filament::class, /** * Email column * * The column to store the email in. */ 'email_column_name' => 'email', /** * After password reset redirect to * * The route to redirect to after a password reset. By default, the user will be redirected to the login page * using "Filament::getLoginUrl()" */ 'after_password_reset_redirect' => null, /** * Override login route * * There is a bug in laravel where when you change password, the user is redirected to the login page by default. This override * fixes that bug by defining a login route that redirects to your panel's login page. */ 'override_login_route' => true ];
致谢
许可
MIT 许可证(MIT)。有关更多信息,请参阅许可文件。