dongwuge6201 2012-07-18 09:46
浏览 59
已采纳

如何实现雅虎/ Facebook,如客户端计算机特定的Sing-in密封,以保护客户免受网络钓鱼攻击?

We want to implement sign in seal to reduce risk of phishing attacks on client. We want client to know that he is on our site rather than some replica of our site. Some web search got us example of Yahoo Sign-in-seal feature. Can you guys guide me on implementing such a system?

Details I would like to have suggestions on are specifically database design and whether mechanism will work with cookies or something else, and are there beter solutions for our requirement than Yahoo sign-in seal.

  • 写回答

1条回答 默认 最新

  • drvxclagw656708070 2012-07-18 10:00
    关注

    Have an area of the site where the user can enter some text or select an image. Store this result in your database against the users ID.

    Once this is done, encrypt this value and set it in a cookie.

    // Set a secret key
    define('SECRET_KEY', 'HNBG:^yhCY*1omNhRg&');
    // Sign in text - get this from the users row in the database
    $signinSeal = 'Hello, User!';
    
    // Encrypt value
    $ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($ivSize, MCRYPT_RAND);
    $encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SECRET_KEY, $signinSeal, MCRYPT_MODE_ECB, $iv);
    // Concat with IV - base64 so it can be safely sent
    $encrypted = base64_encode($iv) . '|' . base64_encode($encrypted);
    
    // Set in a cookie - mark as HTTP only to prevent it being stolen in an XSS attack
    setcookie('signinSeal', $encrypted, time() + (60 * 60 * 24 * 30), '/', 'example.com', false, true);
    

    Now when a user visits your login page, check for the presence of 'signinSeal' cookie, base64 decode it, decrypt and display

    if (array_key_exists('signinSeal', $_COOKIE) && !empty($_COOKIE['signinSeal'])) {
        // Split IV and encrypted string
        $fields = explode('|', $_COOKIE['signinSeal']);
        $iv = base64_decode($fields[0]);
        $encrypted = base64_decode($fields[1]);
        // Decrypt value
        $ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, SECRET_KEY, $encrypted, MCRYPT_MODE_ECB, $iv);
    
        // And display to the user
        echo htmlspecialchars($decrypted);
    }
    

    Once they've logged in - I would set the cookie again, to make sure it doesn't expire

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

报告相同问题?

悬赏问题

  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?