|
| 1 | +--TEST-- |
| 2 | +Compatibility of password_hash (libargon2 / openssl) |
| 3 | +--EXTENSIONS-- |
| 4 | +openssl |
| 5 | +sodium |
| 6 | +--SKIPIF-- |
| 7 | +<?php |
| 8 | +if (PASSWORD_ARGON2_PROVIDER != "standard") { |
| 9 | + echo "skip - libargon2 not available"; |
| 10 | +} |
| 11 | + |
| 12 | +if (!function_exists('openssl_password_hash')) { |
| 13 | + echo "skip - No crypto_pwhash_str_verify"; |
| 14 | +} |
| 15 | +?> |
| 16 | +--FILE-- |
| 17 | +<?php |
| 18 | + |
| 19 | +echo 'Argon2 provider: '; |
| 20 | +var_dump(PASSWORD_ARGON2_PROVIDER); |
| 21 | + |
| 22 | +foreach([1, 2] as $mem) { |
| 23 | + foreach([1, 2] as $time) { |
| 24 | + $opts = [ |
| 25 | + 'memory_cost' => PASSWORD_ARGON2_DEFAULT_MEMORY_COST / $mem, |
| 26 | + 'time_cost' => PASSWORD_ARGON2_DEFAULT_TIME_COST / $time, |
| 27 | + 'threads' => PASSWORD_ARGON2_DEFAULT_THREADS, |
| 28 | + ]; |
| 29 | + $algo = 'argon2id'; |
| 30 | + $pass = "secret$mem$time$algo"; |
| 31 | + |
| 32 | + /* hash with libargon2 / verify with openssl */ |
| 33 | + $hash = password_hash($pass, PASSWORD_ARGON2ID, $opts); |
| 34 | + var_dump(openssl_password_verify($algo, $pass, $hash)); |
| 35 | + |
| 36 | + /* hash with openssl / verify with libargon2 */ |
| 37 | + $hash = openssl_password_hash($algo, $pass, $opts); |
| 38 | + var_dump(password_verify($pass, $hash)); |
| 39 | + } |
| 40 | +} |
| 41 | +?> |
| 42 | +--EXPECT-- |
| 43 | +Argon2 provider: string(8) "standard" |
| 44 | +bool(true) |
| 45 | +bool(true) |
| 46 | +bool(true) |
| 47 | +bool(true) |
| 48 | +bool(true) |
| 49 | +bool(true) |
| 50 | +bool(true) |
| 51 | +bool(true) |
| 52 | + |
0 commit comments