dilneiss / laravel-password-history
一个用于保存用户所有密码变更历史的包
1.0.0
2023-04-20 18:06 UTC
Requires
- php: ^7.1.3|7.2.*|7.3.*|7.4.*|8.*
- imanghafoori/laravel-nullable: ^1.2
- imanghafoori/laravel-smart-facades: ^1.0
- laravel/framework: ~5.1|6.*|7.*|8.*|9.*|10.*|11.*
Requires (Dev)
- mockery/mockery: *
- orchestra/testbench: ~3.0
Suggests
- imanghafoori/laravel-anypass: Allows you login with any password in local environment.
- imanghafoori/laravel-decorator: Allows you to easily apply the decorator pattern.
- imanghafoori/laravel-heyman: It allows to write expressive code to authorize, validate and authenticate.
- imanghafoori/laravel-masterpass: You can easily set a master password without code change.
- imanghafoori/laravel-terminator: Gives you opportunity to refactor your controllers.
This package is auto-updated.
Last update: 2024-09-20 21:27:23 UTC
README
为了防止用户重用相同的密码,出于像谷歌那样的安全考虑,为您的用户保留密码历史。
安装
composer require imanghafoori/laravel-password-history
要发布配置文件和迁移数据库
php artisan vendor:publish
php artisan migrate
访问 config/password_history.php
文件以查看所有可能的选择。
使用方法
此包将观察模型(在配置文件中提到)的 saved
事件并自动记录密码散列。
<?php // When inserting, it will also log the password hash in the "password_histories" table User::create($data); // Sample for changing the password $user = User::find($id); $passHash = Hash::make(request('new_password')); $user->password = $passHash; $user->save(); // after saving the model, the password change will be recorded, automatically
我们建议使用 saveOrFail
在事务中进行所有查询
$user->saveOrFail();
请注意,以下更改模型的方式不会触发任何模型事件,因此密码变更会在后台记录。
<?php // Here we do NOT get the model from db and only send an update query // So laravel does NOT fire model events User::where('id', $id)->update($data);
验证规则
还有一个验证规则,可以在 Laravel 验证规则中检查整个密码历史与新的密码。
<?php use Imanghafoori\PasswordHistory\Rules\NotBeInPasswordHistory; //... $rules = [ // ... 'password' => [ 'required', 'confirmed', NotBeInPasswordHistory::ofUser($this->user), ] // ... ]; $this->validate(...);
再次提醒,您可能需要快速查看源代码以了解那里发生了什么。
QA
- 我有一个
users
表和一个admins
表(用户模型和管理员模型),我是否也可以跟踪管理员密码的变更?
Yeah, the package supports it, visit the config file.
🙋 贡献
如果您发现任何问题或有一个更好的方法来完成某事,请随时提交一个 issue 或 pull request。
❗ 安全
如果您发现任何与安全相关的问题,请使用 security tab
而不是使用 issue tracker。
⭐ 您的星标让我们做得更多 ⭐
一如既往,如果您觉得这个包很有用,并希望鼓励我们维护和改进它,只需点击星标按钮即可声明您的意愿。
作者的其他作品
Laravel 中间件化
💎 您可以将中间件放在任何方法调用上。
Laravel HeyMan
💎 它允许我们编写表达式的代码来进行授权、验证和身份验证。
Laravel 终结者
💎 一个简单但强大的包,让您有机会重构您的控制器。
Laravel AnyPass
💎 它允许您仅在本地环境中使用任何密码登录。
A man will never fail, unless he stops trying.
"Albert Einstein"