throttling - Laravel 6:油门密码重置
问题描述
在 laravel 6 中,密码代理现在具有以下限制密码重置(https://github.com/laravel/framework/blob/6.x/src/Illuminate/Auth/Passwords/PasswordBroker.php#L58)
public function sendResetLink(array $credentials)
{
// First we will check to see if we found a user at the given credentials and
// if we did not we will redirect back to this current URI with a piece of
// "flash" data in the session to indicate to the developers the errors.
$user = $this->getUser($credentials);
if (is_null($user)) {
return static::INVALID_USER;
}
if (method_exists($this->tokens, 'recentlyCreatedToken') &&
$this->tokens->recentlyCreatedToken($user)) {
return static::RESET_THROTTLED;
}
// Once we have the reset token, we are ready to send the message out to this
// user with a link to reset their password. We will then redirect back to
// the current URI having nothing set in the session to indicate errors.
$user->sendPasswordResetNotification(
$this->tokens->create($user)
);
return static::RESET_LINK_SENT;
}
但是,当我反复提交密码重置时,为什么密码重置没有受到限制 - 我仍然收到重置通知?
我注意到该recentlyCreatedToken
方法在 6.x 版本的 TokenRepositoryInterface 中不存在https://github.com/laravel/framework/blob/6.x/src/Illuminate/Auth/Passwords/TokenRepositoryInterface.php
但已在 7.x 版本中添加
这只是 v7.x 的一个功能,还是我需要做一些我错过的事情?
解决方案
密码重置限制在 Laravel 6.x 中有效,但由于某种原因,您需要throttle
在配置文件中手动设置参数config/auth.php
:
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60, // Allows a user to request 1 token per 60 seconds
],
],
DatabaseTokenRepository将节流时间的默认值定义为 60 秒。但是当在PasswordBrokerManager中初始化 DatabaseTokenRepository 时,它会检查配置文件,如果没有找到值,则将节流时间设置为 0(意味着禁用节流)。
您还需要添加消息字符串以resources/lang/en/passwords.php
向用户显示可理解的错误消息:
'throttled' => 'You have requested password reset recently, please check your email.',
PS不要忘记在编辑配置文件后刷新配置缓存php artisan config:clear
。
推荐阅读
- android - Delphi FireMonkey在android系统上强制引发触摸事件
- oracle - 我在 Amazon RDS 中有哪些选项可以使用“fixed_date”?
- python - 在熊猫数据框中运行折扣价
- php - 如何在 PHP 中使用 stacktrace 保存代码行?
- r - 用 R 重塑表格
- react-native - tensorflow-models/mobilenet 在设备离线时不工作
- r - 使用 geom_text 避免重叠标签
- tinkercad - Tinkercad 中函数发生器和示波器的混淆标签
- python - Sumo,TraCI:使用 tc.VAR_ROUTE 和 tc.VAR_FOLLOWER 订阅失败。我可以将哪些订阅变量用于车辆?
- reactjs - 更改材质 ui IconButton 悬停样式不起作用