php Na钠_crypto_pHash_str_verify()失败
我试图弄清楚如何使用php7.2中新的php Na钠_crypto_pHash_str_verify()失败,php,libsodium,Php,Libsodium,我试图弄清楚如何使用php7.2中新的libnadium功能,但由于某种原因,我似乎无法让nadium\u crypto\u phash\u str\u verify()正常工作 我决定在他们的文档中实际使用给定的示例: LibNade自身的示例代码: 注意:关于示例代码,我已经联系了作者,现在已经联系过了 已经修好了!所以下面的例子已经过时了。(2018-05-30) (我所做的唯一调整是$passwort=“test”和echos) 您的$password和$storeInDatabase方
libnadium
功能,但由于某种原因,我似乎无法让nadium\u crypto\u phash\u str\u verify()
正常工作
我决定在他们的文档中实际使用给定的示例:
LibNade自身的示例代码:
注意:关于示例代码,我已经联系了作者,现在已经联系过了
已经修好了!所以下面的例子已经过时了。(2018-05-30)
(我所做的唯一调整是$passwort=“test”
和echo
s)
您的$password
和$storeInDatabase
方法错误
应该是:
if(钠密码校验($storeInDatabase,$password)){
从文档中:
bool-nasdina\u-crypto\u-pwash\u-str\u-verify(string$hash,string$password)
你是对的-它是这样工作的。虽然从技术上讲,不是我把参数搞错了,而是libnasdina示例代码!我想我会给他们发个信息:)
<?php
$password = "test"; // by me
/* This uses Argon2i with two numeric constants that correspond to
* the number of passes (OPSLIMIT) and the amount of memory to use
* (MEMLIMIT). A higher OPSLIMIT helps against CPU attacks, while a
* higher MEMLIMIT helps against GPU attacks.
*/
$storeInDatabase = sodium_crypto_pwhash_str(
$password,
SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
);
/* Once that's stored, you can just test against the hash like so: */
if (sodium_crypto_pwhash_str_verify($password, $storeInDatabase)) {
/* Logged in! */
echo "works!"; // by me
} else {
/* Incorrect password. */
echo "failed!"; // by me
}