3v4l.org

run code in 300+ PHP versions simultaneously
<?php function password_encrypt($password){ $hash_format = "$2y$10$"; $salt_length = 22; $salt = generate_salt($salt_length); $format_and_salt = $hash_format . $salt; $hash = crypt($password, $format_and_salt); return $hash; } function generate_salt($length){ // Not 100% unique, not 100% random, but good enough for a salt // MD5 returns 32 characters $unique_random_string = md5(uniqid(mt_rand(), true)); // Valid characters for a salt are [a-zA-Z0-9./] $base64_string = base64_encode($unique_random_string); // But not '+' which is valid in base64 encoding $modified_base64_string = str_replace('+', '.', $base64_string); // Truncate string to the correct length $salt = substr($modified_base64_string, 0, $length); return $salt; } function password_check($password, $existing_hash) { // existing hash contains format and salt at start $hash = crypt($password, $existing_hash); if ($hash === $existing_hash) { return true; } else { return false; } } if(password_check(3301386, "$2y$10$MzU3ODMzOGE0MGEwMzI3OOi8QVkhZmXTwdWbdx9c7F6DxuZyyAO2q"){ echo "found!"; }
Output for 7.0.0 - 7.0.9
Parse error: syntax error, unexpected 'echo' (T_ECHO) in /in/1rl6t on line 38
Process exited with code 255.
Output for 5.6.0 - 5.6.24
Parse error: syntax error, unexpected '{' in /in/1rl6t on line 37
Process exited with code 255.

preferences:
166.26 ms | 1394 KiB | 42 Q