1--TEST-- 2Check for libsodium argon2i 3--EXTENSIONS-- 4sodium 5--SKIPIF-- 6<?php 7if (!defined('SODIUM_CRYPTO_PWHASH_SALTBYTES')) print "skip libsodium without argon2i"; ?> 8--FILE-- 9<?php 10$passwd = 'password'; 11 12$hash = sodium_crypto_pwhash_str 13 ($passwd, SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, 14 SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE); 15var_dump(substr($hash, 0, strlen(SODIUM_CRYPTO_PWHASH_STRPREFIX)) === 16 SODIUM_CRYPTO_PWHASH_STRPREFIX); 17 18$testHash = '$argon2i$v=19$m=4096,t=3,p=1$MzE4ODFiZWFlMjAzOWUAAA$FWUV6tsyJ32qThiLi1cCsLIbf3dIOG/RwXcTzt536KY'; 19$c = sodium_crypto_pwhash_str_verify($testHash, $passwd); 20var_dump($c); 21 22$testHash = '$argon2i$v=19$m=4096,t=0,p=1$c29tZXNhbHQAAAAAAAAAAA$JTBozgKQiCn5yKAm3Hz0vUSX/XgfqhZloNCxDWmeDr0'; 23$c = sodium_crypto_pwhash_str_verify($testHash, $passwd); 24var_dump($c); 25 26$c = sodium_crypto_pwhash_str_verify($hash, $passwd); 27var_dump($c); 28 29$c = sodium_crypto_pwhash_str_verify($hash, 'passwd'); 30var_dump($c); 31 32$salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES); 33$out_len = 100; 34$key = sodium_crypto_pwhash 35 ($out_len, $passwd, $salt, 36 SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, 37 SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE, 38 SODIUM_CRYPTO_PWHASH_ALG_DEFAULT); 39var_dump(strlen($key) === $out_len); 40$key2 = sodium_crypto_pwhash 41 ($out_len, $passwd, $salt, 42 SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, 43 SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE); 44var_dump($key2 === $key); 45?> 46--EXPECT-- 47bool(true) 48bool(true) 49bool(false) 50bool(true) 51bool(false) 52bool(true) 53bool(true) 54