|
| 1 | +--TEST-- |
| 2 | +Test interoperability of password_hash('argon2id') |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +if (!function_exits('sodium_crypto_pwhash_str_verify')) { |
| 6 | + echo "skip - No crypto_pwhash_str_verify"; |
| 7 | +} |
| 8 | +if (!in_array('argon2id', password_algos(), true /* strict */)) { |
| 9 | + echo "skip - No argon2id support in password_hash()"; |
| 10 | +} |
| 11 | +--FILE-- |
| 12 | +<?php |
| 13 | + |
| 14 | +foreach([1, 2, 4] as $mem) { |
| 15 | + foreach([1, 2, 4] as $time) { |
| 16 | + foreach([1, 2, 4] as $threads) { |
| 17 | + $opts = [ |
| 18 | + 'memory_cost' => PASSWORD_ARGON2_DEFAULT_MEMORY_COST * $mem, |
| 19 | + 'time_cost' => PASSWORD_ARGON2_DEFAULT_TIME_COST * $time, |
| 20 | + 'threads' => PASSWORD_ARGON2_DEFAULT_THREADS * $threads, |
| 21 | + ]; |
| 22 | + $password = random_bytes(32); |
| 23 | + echo "Using password: "; |
| 24 | + var_dump(base64_encode($password)); |
| 25 | + $hash = password_hash($password, 'argon2id', $opts); |
| 26 | + echo "Hash: "; var_dump($hash); |
| 27 | + var_dump(sodium_crypto_pwhash_str_verify($hash, $password)); |
| 28 | + } |
| 29 | + } |
| 30 | +} |
| 31 | +--EXPECTF-- |
| 32 | +Using password: string(44) "%s" |
| 33 | +Hash: string(96) "$argon2id$v=19$m=1024,t=3,p=2$%s" |
| 34 | +bool(true) |
| 35 | +Using password: string(44) "%s" |
| 36 | +Hash: string(96) "$argon2id$v=19$m=1024,t=3,p=4$%s" |
| 37 | +bool(true) |
| 38 | +Using password: string(44) "%s" |
| 39 | +Hash: string(96) "$argon2id$v=19$m=1024,t=3,p=8$%s" |
| 40 | +bool(true) |
| 41 | +Using password: string(44) "%s" |
| 42 | +Hash: string(96) "$argon2id$v=19$m=1024,t=6,p=2$%s" |
| 43 | +bool(true) |
| 44 | +Using password: string(44) "%s" |
| 45 | +Hash: string(96) "$argon2id$v=19$m=1024,t=6,p=4$%s" |
| 46 | +bool(true) |
| 47 | +Using password: string(44) "%s" |
| 48 | +Hash: string(96) "$argon2id$v=19$m=1024,t=6,p=8$%s" |
| 49 | +bool(true) |
| 50 | +Using password: string(44) "%s" |
| 51 | +Hash: string(97) "$argon2id$v=19$m=1024,t=12,p=2$%s" |
| 52 | +bool(true) |
| 53 | +Using password: string(44) "%s" |
| 54 | +Hash: string(97) "$argon2id$v=19$m=1024,t=12,p=4$%s" |
| 55 | +bool(true) |
| 56 | +Using password: string(44) "%s" |
| 57 | +Hash: string(97) "$argon2id$v=19$m=1024,t=12,p=8$%s" |
| 58 | +bool(true) |
| 59 | +Using password: string(44) "%s" |
| 60 | +Hash: string(96) "$argon2id$v=19$m=2048,t=3,p=2$%s" |
| 61 | +bool(true) |
| 62 | +Using password: string(44) "%s" |
| 63 | +Hash: string(96) "$argon2id$v=19$m=2048,t=3,p=4$%s" |
| 64 | +bool(true) |
| 65 | +Using password: string(44) "%s" |
| 66 | +Hash: string(96) "$argon2id$v=19$m=2048,t=3,p=8$%s" |
| 67 | +bool(true) |
| 68 | +Using password: string(44) "%s" |
| 69 | +Hash: string(96) "$argon2id$v=19$m=2048,t=6,p=2$%s" |
| 70 | +bool(true) |
| 71 | +Using password: string(44) "%s" |
| 72 | +Hash: string(96) "$argon2id$v=19$m=2048,t=6,p=4$%s" |
| 73 | +bool(true) |
| 74 | +Using password: string(44) "%s" |
| 75 | +Hash: string(96) "$argon2id$v=19$m=2048,t=6,p=8$%s" |
| 76 | +bool(true) |
| 77 | +Using password: string(44) "%s" |
| 78 | +Hash: string(97) "$argon2id$v=19$m=2048,t=12,p=2$%s" |
| 79 | +bool(true) |
| 80 | +Using password: string(44) "%s" |
| 81 | +Hash: string(97) "$argon2id$v=19$m=2048,t=12,p=4$%s" |
| 82 | +bool(true) |
| 83 | +Using password: string(44) "%s" |
| 84 | +Hash: string(97) "$argon2id$v=19$m=2048,t=12,p=8$%s" |
| 85 | +bool(true) |
| 86 | +Using password: string(44) "%s" |
| 87 | +Hash: string(96) "$argon2id$v=19$m=4096,t=3,p=2$%s" |
| 88 | +bool(true) |
| 89 | +Using password: string(44) "%s" |
| 90 | +Hash: string(96) "$argon2id$v=19$m=4096,t=3,p=4$%s" |
| 91 | +bool(true) |
| 92 | +Using password: string(44) "%s" |
| 93 | +Hash: string(96) "$argon2id$v=19$m=4096,t=3,p=8$%s" |
| 94 | +bool(true) |
| 95 | +Using password: string(44) "%s" |
| 96 | +Hash: string(96) "$argon2id$v=19$m=4096,t=6,p=2$%s" |
| 97 | +bool(true) |
| 98 | +Using password: string(44) "%s" |
| 99 | +Hash: string(96) "$argon2id$v=19$m=4096,t=6,p=4$%s" |
| 100 | +bool(true) |
| 101 | +Using password: string(44) "%s" |
| 102 | +Hash: string(96) "$argon2id$v=19$m=4096,t=6,p=8$%s" |
| 103 | +bool(true) |
| 104 | +Using password: string(44) "%s" |
| 105 | +Hash: string(97) "$argon2id$v=19$m=4096,t=12,p=2$%s" |
| 106 | +bool(true) |
| 107 | +Using password: string(44) "%s" |
| 108 | +Hash: string(97) "$argon2id$v=19$m=4096,t=12,p=4$%s" |
| 109 | +bool(true) |
| 110 | +Using password: string(44) "%s" |
| 111 | +Hash: string(97) "$argon2id$v=19$m=4096,t=12,p=8$%s" |
| 112 | +bool(true) |
0 commit comments