duanlaican1849 2015-10-06 11:33
浏览 195
已采纳

Laravel 5如果密码重置令牌已过期,如何检查密码重置令牌

I'm developing a web app using Laravel 5, I used Laravel's make:auth scaffolding. I was able to send a password reset link with a token, which works well on my end. I have this kind of url after clicking on the reset link: http://example.com/password/reset/{reset_token}. Now, on my auth.reset blade file, I want to check first if the {reset_token} has already expired because it seems in the 60 minutes expiration time at config.auth.php, it doesn't seem to automatically remove expired tokens. So, I'm trying to make a manual function to check if reset token is still valid with this:

function validateReminderToken($token)
{
    // I want to add some filter here like
    // if (tokenExpired($token)) return false;     
    $res = DB::table('password_resets')->where('token', $token)->get();
    if (empty($res)  || $res === null) {
        return false;
    }

    $res = $res[0];
    return $res->email;
}

How can I do it? Is there some built-in way of checking if the token has expired? Thanks.

  • 写回答

4条回答 默认 最新

  • douxin1956 2015-10-06 12:04
    关注

    Use the created_at to check if a certain duration has passed from the time of insertion. For example you can do like so :

    $token = DB::table('password_resets')
        ->where('token','=',$token)
        ->where('created_at','>',Carbon::now()->subHours(2))
        ->first();
    

    Then check if the token exists.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 matlab求解平差
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?