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.

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

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了