-1

我正在建立一个网站的客户在其“仅限会员”部分使用密码/促销代码,允许会员访问特殊内容。我通过 MySQL 存储所述密码,使用 sha1 加密。

客户端需要在管理员控制面板中以纯文本形式查看这些密码。显然,这不是使用 sha1 的选项。

加密数据库中的密码与存储纯文本之间的权衡是什么?我应该简单地将它们以纯文本形式存储在数据库中,然后在帖子中加盐吗?

在保持适当安全级别的同时能够显示纯文本密码的最佳方法是什么?

4

6 回答 6

3

不显示密码。只需为客户端提供以其他用户身份登录的能力(我认为这就是他们需要密码的原因吗?)也许是在一个页面上,该页面本身受密码保护,只有客户端知道。

于 2013-04-30T05:19:53.443 回答
2

您应该向您的客户解释为什么他们必须无权访问密码。很多事情都可能出错。被盗的数据库,流氓用户,错过了 SQL 注入攻击,这不值得冒险。

于 2013-04-30T05:22:10.747 回答
1

不要这样做。寻找替代路线。

如果您的客户出于某种原因想要查看其用户的密码,请询问他们为什么要查看这些密码,以及如果他们有这些密码他们会怎么做 - 然后为他们提供另一种直接的方法,这种方法永远不会涉及必须知道用户的密码是什么。

无论您的客户使用多么无辜或多么轻微,大多数人都会在任何地方重复使用他们的密码。您的客户可能会认为他们只知道用户自己系统的密码,但这意味着他们现在可能知道用户的所有密码——电子邮件、网上银行等金融服务等。

只需一名恶意员工和一名用户的帐户在互联网上的其他地方遭到入侵。除了某人的隐私遭到侵犯之外,这可能是一个相当合法的泥潭。

寻找替代方案。永远不要以纯文本形式显示用户的密码。

于 2013-04-30T05:34:59.840 回答
1

This can do it.

<?php
    # --- ENCRYPTION ---

    # the key should be random binary, use scrypt, bcrypt or PBKDF2 to
    # convert a string into a key
    # key is specified using hexadecimal
    $key = pack('H*', "bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3");

    # show key size use either 16, 24 or 32 byte keys for AES-128, 192
    # and 256 respectively
    $key_size =  strlen($key);
    echo "Key size: " . $key_size . "\n";

    $plaintext = "This string was AES-256 / CBC / ZeroBytePadding encrypted.";

    # create a random IV to use with CBC encoding
    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);

    # use an explicit encoding for the plain text
    $plaintext_utf8 = utf8_encode($plaintext);

    # creates a cipher text compatible with AES (Rijndael block size = 128)
    # to keep the text confidential 
    # only suitable for encoded input that never ends with value 00h
    # (because of default zero padding)
    $ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key,
                                 $plaintext_utf8, MCRYPT_MODE_CBC, $iv);

    # prepend the IV for it to be available for decryption
    $ciphertext = $iv . $ciphertext;

    # encode the resulting cipher text so it can be represented by a string
    $ciphertext_base64 = base64_encode($ciphertext);

    echo  $ciphertext_base64 . "\n";

    # === WARNING ===

    # Resulting cipher text has no integrity or authenticity added
    # and is not protected against padding oracle attacks.

    # --- DECRYPTION ---

    $ciphertext_dec = base64_decode($ciphertext_base64);

    # retrieves the IV, iv_size should be created using mcrypt_get_iv_size()
    $iv_dec = substr($ciphertext_dec, 0, $iv_size);

    # retrieves the cipher text (everything except the $iv_size in the front)
    $ciphertext_dec = substr($ciphertext_dec, $iv_size);

    # may remove 00h valued characters from end of plain text
    $plaintext_utf8_dec = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key,
                                         $ciphertext_dec, MCRYPT_MODE_CBC, $iv_dec);

    echo  $plaintext_utf8_dec . "\n";
?>

Source: http://www.php.net/manual/en/function.mcrypt-encrypt.php

于 2013-04-30T05:24:47.160 回答
1

您可以使用双向加密来存储和显示密码。mcrypt_encrypt()mcrypt_decrypt。看这个问题最简单的使用PHP的双向加密

于 2013-04-30T05:26:31.633 回答
0

It was stored using SHA1 so it cannot be retrieved in cleartext because SHA1 is a one-way hash. You can't convert it to original form. http://php.net/manual/en/function.sha1.php

So either you can go for md5 format or simply store them in the database as plain-text, and just salt them in post

于 2013-04-30T05:23:25.110 回答