imanghafoori / laravel-password-history
一个用于记录用户所有密码更改历史的包
v1.0.2
2023-04-07 17:09 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.
README
为了防止用户重复使用相同的密码,出于像Google一样的安全考虑,可以记录用户密码的历史。
安装
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
表(User模型和Admin模型),我能追踪管理员的密码更改吗?
Yeah, the package supports it, visit the config file.
🙋 贡献
如果您发现任何问题或有一个更好的方法来做某事,请随意提交一个问题或pull请求。
❗ 安全
如果您发现任何与安全相关的问题,请使用安全标签
而不是使用问题跟踪器。
⭐ 您的星标让我们做得更多 ⭐
一如既往,如果您认为这个包很有用,并希望鼓励我们维护并改进它,只需按下星标按钮即可声明您的意愿。
作者的其他作品
Laravel中间件化
💎 您可以在任何方法调用上放置中间件。
Laravel HeyMan
💎 允许我们编写表达式代码来进行授权、验证和认证。
Laravel终止者
💎 一个功能强大但简单的包,可以为您提供重构控制器的机会。
Laravel AnyPass
💎 仅在本地环境中允许您使用任何密码登录。
A man will never fail, unless he stops trying.
"Albert Einstein"