doutang3815 2013-10-24 05:59
浏览 657
已采纳

如何在使用php的登录系统中使用nonce以避免重放攻击?

I have created a login and registration system using php. I intend to use nonces to prevent the replay attack. So far what I have is, generating a random number using (uniqid(mt_rand(),true)); and then store this on the database, and pass the same data in a hidden field to the client end, and then send it back to the server side, when the login button is clicked. if it matches the on in the database, the user is redirected to the private page, and then a new nonce is generated and updated in the database.

This is how i intend to implement it. But I'm some how not totally sure of the implementation.

  • 写回答

3条回答 默认 最新

  • drsqpko5286 2013-10-24 06:47
    关注
    <?php
    session_start();
    //Check nonce against session
    if(isset($_POST) && $_POST["nonce"] === $_SESSION["csrf"]){
        //save data
        //redirect
    }
    //generate new nonce for form
    $_SESSION["csrf"] = uniqid(mt_rand(),true);
    ?>
    <form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
        <input type="hidden" name="nonce" value="<?php echo $_SESSION['csrf']; ?>"/>
        <!-- other form fields -->
        <!-- submit button -->
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题