douchuitang0331 2017-04-11 12:46
浏览 22
已采纳

使用唯一密码在Laravel中密码保护页面[关闭]

I need to set up password protected pages within laravel (using 5.4), each page entry in my database has a password field.

I want to be able to only access the page if the password is correctly entered...

I think this makes sense and I can't seem to find anything else on this other than using the built in auth functionality of laravel...

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • douyi1963 2017-04-11 13:03
    关注

    This is a pretty simple thing to do..

    Create a form with a password field and a hidden id field where you store the id of the page you want to access.

    When user submits the password, check if it matches the one in your database..

    if (Hash::check('enetered-password', $hashedPassword)) {
        // The passwords match...
    }
    

    If so, store the page id in an array in the session. Next time the user wants to visit the page, you check if the id exists in this array, if so redirect to the page, otherwise redirect to the password form page.

    It would be even wiser to add a middleware to the protected pages, to check if the user has permission or not and also redirect.

    Once the session expires (i.e. use logs out) all data will be destroyed, so if they login again, they need to enter the page passwords again.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度