[英]How can i generate a token which will expire after some time just like the token field in password_reset table in laravel 5.1?
/*
|--------------------------------------------------------------------------
| Password Reset Settings
|--------------------------------------------------------------------------
|
| Here you may set the options for resetting passwords including the view
| that is your password reset e-mail. You can also set the name of the
| table that maintains all of the reset tokens for your application.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'password' => [
'email' => 'emails.password',
'table' => 'password_resets',
'expire' => 60,
],
我想生成一個令牌,就像該password_resets表中的令牌一樣。 但是我不明白這是如何工作的。
如果你想在DatabaseTokenRepository店令牌,你可以使用Illuminate\\Auth\\Passwords\\DatabaseTokenRepository
它實現了Illuminate\\Auth\\Passwords\\TokenRepositoryInterface
接口。 它也被注冊為'auth.password.tokens'
。
create方法具有一個必需的參數才能工作。 這是簽名:
/**
* Create a new token record.
*
* @param \Illuminate\Contracts\Auth\CanResetPassword $user
* @return string
*/
public function create(CanResetPasswordContract $user);
此類由實現Illuminate\\Contracts\\Auth\\PasswordBroker
接口的Illuminate\\Auth\\Passwords\\PasswordBroker
類使用。 在這里,您可以看到存儲庫的用法示例。
注意:如果要使用PasswordBroker,請嘗試app()->make('auth.password')
。
在password_resets
表中,有三個字段: email,token,created_at
。 生成令牌時,日期時間存儲在created_at
字段中。 使用此令牌時,請檢查該令牌是否早於到期時間。 如果是,則令牌無效,否則有效。 執行您的過程,並在兩種情況下銷毀該令牌。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.