3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); /** * Verify a Django password (PBKDF2-SHA256) * * @param string $password The password provided by the user * @param string $djangoHash The hash stored in the Django app * @return bool * @throws Exception */ function django_password_verify(string $password, string $djangoHash): bool { $pieces = explode('$', $djangoHash); if (count($pieces) !== 4) { throw new Exception("Illegal hash format"); } list($header, $iter, $salt, $hash) = $pieces; // Get the hash algorithm used: if (preg_match('#^pbkdf2_([a-z0-9A-Z]+)$#', $header, $m)) { $algo = $m[1]; } else { throw new Exception(sprintf("Bad header (%s)", $header)); } if (!in_array($algo, hash_algos())) { throw new Exception(sprintf("Illegal hash algorithm (%s)", $algo)); } $calc = hash_pbkdf2($algo, $password, base64_decode($salt), (int) $iterations); var_dump($calc); return false; } var_dump(django_password_verify('123', 'pbkdf2_sha256$20000$MflWfLXbejfO$tNrjk42YE9ZXkg7IvXY5fikbC+H52Ipd2mf7m0azttk='));
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
Warning: Undefined variable $iterations in /in/KVaSt on line 29 Fatal error: Uncaught ValueError: hash_pbkdf2(): Argument #4 ($iterations) must be greater than 0 in /in/KVaSt:29 Stack trace: #0 /in/KVaSt(29): hash_pbkdf2('sha256', Object(SensitiveParameterValue), '1\xF9V|\xB5\xDBz7\xCE', 0) #1 /in/KVaSt(34): django_password_verify('123', 'pbkdf2_sha256$2...') #2 {main} thrown in /in/KVaSt on line 29
Process exited with code 255.
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33
Warning: Undefined variable $iterations in /in/KVaSt on line 29 Fatal error: Uncaught ValueError: hash_pbkdf2(): Argument #4 ($iterations) must be greater than 0 in /in/KVaSt:29 Stack trace: #0 /in/KVaSt(29): hash_pbkdf2('sha256', '123', '1\xF9V|\xB5\xDBz7\xCE', 0) #1 /in/KVaSt(34): django_password_verify('123', 'pbkdf2_sha256$2...') #2 {main} thrown in /in/KVaSt on line 29
Process exited with code 255.
Output for 7.0.0 - 7.0.31, 7.1.0 - 7.1.23, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined variable: iterations in /in/KVaSt on line 29 Warning: hash_pbkdf2(): Iterations must be a positive integer: 0 in /in/KVaSt on line 29 bool(false) bool(false)
Output for 7.3.32 - 7.3.33
Warning: hash_pbkdf2(): Iterations must be a positive integer: 0 in /in/KVaSt on line 29 bool(false) bool(false)
Output for 5.6.0 - 5.6.38
Warning: Unsupported declare 'strict_types' in /in/KVaSt on line 2 Parse error: syntax error, unexpected ':', expecting '{' in /in/KVaSt on line 12
Process exited with code 255.

preferences:
195.03 ms | 413 KiB | 5 Q