- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
像大多数用户一样,我只是想找出一种安全的方式来存储密码。我在这里没有找到(或者可能是我缺乏理解)是如何在我的数据库中检索加盐散列并将盐与散列密码分开,尤其是每个密码都有唯一的盐,而将盐+密码保存在单个列中。
我正在寻找所有这些很酷的方法来加密密码(SHA-256,但 MySQL 是否只支持 SHA/1 和 MD5?)以及 PHP 手册中的其他内容,但不确定如何存储和检索密码。
所以,到目前为止,我所了解的就这些了:
SHA('$salt'.'$password') // My query sends the password and salt
// (Should the $salt be a hash itself?)
在那之后我迷失了盐分。
没有盐的情况下检索密码很容易,但是盐让我很困惑。我在哪里可以再次从 $salt 获得值(value),特别是如果它是唯一且安全的?我是否将它们隐藏在另一个数据库中?常量(似乎不安全)?
编辑: HMAC 中的关键变量应该是盐还是其他?
最佳答案
首先,您的 DBMS (MySQL) 不需要对加密哈希提供任何支持。您可以在 PHP 端完成所有这些,这也是您应该做的。
如果你想将 salt 和 hash 存储在同一列中,你需要将它们连接起来。
// the plaintext password
$password = (string) $_GET['password'];
// you'll want better RNG in reality
// make sure number is 4 chars long
$salt = str_pad((string) rand(1, 1000), 4, '0', STR_PAD_LEFT);
// you may want to use more measures here too
// concatenate hash with salt
$user_password = sha512($password . $salt) . $salt;
现在,如果您想验证密码,您可以:
// the plaintext password
$password = (string) $_GET['password'];
// the hash from the db
$user_password = $row['user_password'];
// extract the salt
// just cut off the last 4 chars
$salt = substr($user_password, -4);
$hash = substr($user_password, 0, -4);
// verify
if (sha512($password . $salt) == $hash) {
echo 'match';
}
您可能想看看 phpass ,它也使用了这种技术。它是一种 PHP 哈希解决方案,在其他一些东西中使用了加盐。
您一定要看看 WolfOdrade 链接到的问题的答案。
关于php - 用 PHP 和 MySQL 给我的哈希加盐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3273293/
我正在阅读有关如何对 key 进行加盐以使您的加密安全的教程,但无法充分利用它。我不太了解密码学,需要一些帮助。我正在使用 commoncrypto 来加密文件,并且完成了,除了它不安全的事实....
我是一个加密新手,但需要在存储到数据库之前对敏感的个人数据进行加密。我计划将 AES 与 CBC 结合使用,但也想使用盐。然而,我找不到一种方法来做到这一点(除了 BouncyCaSTLe,我的主机由
升级到 php7 后,BCryptPasswordEncoder 抛出以下错误,例如在使用 FOSUserBundle 标准注册页面注册时: "Use of the 'salt' option to
这个简单的代码接受用户输入并将给定字符串的 sha256 打印到标准输出。 #include #include #include #include int main() { SHA256_C
我想知道以下设置的严重问题是什么: 用户名/密码登录方案Javascript/ajax 从服务器请求盐值(我们在前面的问题中已经确定盐不是 secret 值)Javascript 对密码和盐执行 SH
我一直在 ruby 应用程序中创建加盐密码,我认为这是标准方式: password_salt = BCrypt::Engine.generate_salt password_hash = BCry
我听说过有人在使用这种方法,想知道这意味着什么。我只是知道这是个坏主意! 据我所知,在将哈希存储到数据库之前对密码进行加盐处理的主要目的是使每个哈希算法都独一无二,因此在尝试破解它时需要为每个用户提供
我需要编码/加密数据库 ID 并将它们附加到我的 URL。安全性不是我要处理的问题,但我正在寻找具有适度安全性的东西。主要目标是拥有唯一且 URL 安全的短 ID。 下面的代码片段似乎可以满足我的需要
我正在使用 RC4 C++ 程序进行更多工作,以与命令行参数兼容。 我想知道是否有人可以指出一些关于命令行 openssl rc4 在加密和解密时如何使用盐的体面文档的方向,这样我就可以在我的程序中加
我有一个字符串需要在 C# 中使用 salt 进行哈希处理并匹配它在 PHP 中的结果。 C#代码如下: string stringToHash = "123"; st
这个问题在这里已经有了答案: 关闭 9 年前。 Possible Duplicate: Secure hash and salt for PHP passwords 我在 stackoverflow
我有一个项目,显然该软件的设计者没有考虑安全性。 密码以明文形式存储并通过明文传输。所以我剩下的任务就是解决这个问题。 我对安全性有点生疏,所以我的问题是:对于在线用户密码身份验证,使用散列/加盐技术
盐的新手,我添加了第一个服务器(wx-1),它可以工作,但是当我添加不同的服务器时,test.ping 没问题,但是当执行 salt 'qing' state.highstate 时,失败,错误信息为
我使用此 openssl 命令创建了一条加密消息: openssl enc -aes-256-cbc -salt -in plaintext.txt -out cipher.enc 我尝试过 Cryp
我正在对许多列执行联接,这些列有时可能包含数十亿行空值,因此我想对列加盐以防止联接后出现倾斜,如 Jason Evan 的帖子中提到的:https://stackoverflow.com/a/4339
我是一名优秀的程序员,十分优秀!