Argon2id 如何在 PHP 中储存盐分?
How does Argon2id store salts in PHP?
Argon2id 的 PHP 实现为开发人员生成了盐。应用程序如何跟踪这种盐?作为一名开发人员,我如何考虑备份并以其他方式确保我不会丢失盐分?
尽管 the documentation for the password_hash()
function labels the function return value the "hash," it is actually a compound string that also incorporates the salt and some metadata to identify which algorithm was used. The companion password_verify()
function 解析此信息以做正确的事情。
所以你只需要存储 password_hash()
的结果。
正如 Luis 所说,盐存储在哈希函数的结果中,由 $
:
分隔
password_hash('secret', PASSWORD_ARGON2I);
会不会return像这样:
$argon2i$v=19$m=1024,t=2,p=2$MEhSZkJLQXUxRzljNE5hMwpvelMsxqOn/1VV2pnjmKJUECBhilzOZ2+Gq/FxCP4
其中:
argon2i
是算法
v=19
是版本
m=1024,t=2,p=2
是内存、迭代和并行选项
MEhSZkJLQXUxRzljNE5hMw
是盐
- 而
33pvelMsxqOn/1VV2pnjmKJUECBhilzOZ2+Gq/FxCP4
是实际的哈希值。
所以你只需要保存整个字符串,它会保留 PHP 哈希方法所需的一切,比如 password_verify
.
Argon2id 的 PHP 实现为开发人员生成了盐。应用程序如何跟踪这种盐?作为一名开发人员,我如何考虑备份并以其他方式确保我不会丢失盐分?
尽管 the documentation for the password_hash()
function labels the function return value the "hash," it is actually a compound string that also incorporates the salt and some metadata to identify which algorithm was used. The companion password_verify()
function 解析此信息以做正确的事情。
所以你只需要存储 password_hash()
的结果。
正如 Luis 所说,盐存储在哈希函数的结果中,由 $
:
password_hash('secret', PASSWORD_ARGON2I);
会不会return像这样:
$argon2i$v=19$m=1024,t=2,p=2$MEhSZkJLQXUxRzljNE5hMwpvelMsxqOn/1VV2pnjmKJUECBhilzOZ2+Gq/FxCP4
其中:
argon2i
是算法v=19
是版本m=1024,t=2,p=2
是内存、迭代和并行选项MEhSZkJLQXUxRzljNE5hMw
是盐- 而
33pvelMsxqOn/1VV2pnjmKJUECBhilzOZ2+Gq/FxCP4
是实际的哈希值。
所以你只需要保存整个字符串,它会保留 PHP 哈希方法所需的一切,比如 password_verify
.