3v4l.org

run code in 300+ PHP versions simultaneously
<?php $RANDOM_SALT = 0; //rand(); function saltedHash($pass) { global $RANDOM_SALT; return hash("sha512", $pass) + $RANDOM_SALT; } $USERS = [ "user1" => saltedHash("password1"), "user2" => saltedHash("hunter2"), "user3" => saltedHash("fN.4A_zKEe]33p!"), "user4" => saltedHash("xXgjan3a58qzX3"), ]; function checkLogIn($username, $password) { global $USERS; $hashedPassword = saltedHash($password); $expectedPassword = $USERS[$username]; echo " H: $hashedPassword\n E: $expectedPassword\n"; echo "User '$username' has password '$password'? "; if ($hashedPassword === $expectedPassword) { echo "yes\n"; } else { echo "no\n"; } } // ==== TEST CODE: ==== checkLogIn("user1", "phplol"); checkLogIn("user1", "password1"); echo "\n"; checkLogIn("user2", "phplol"); checkLogIn("user2", "hunter2"); echo "\n"; checkLogIn("user3", "phplol"); checkLogIn("user3", "FN4A_zKEe]33p!"); echo "\n"; checkLogIn("user4", "phplol"); checkLogIn("user4", "xXgjan3a58qzX3"); echo "\n"; echo "Now let's get funky!"; checkLogIn("user3", "password1"); checkLogIn("user3", "fN.4A_zKEe]33p!"); checkLogIn("user3", "fN.4A_zKEe]33p!");
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught TypeError: Unsupported operand types: string + int in /in/Y9aPg:6 Stack trace: #0 /in/Y9aPg(10): saltedHash('password1') #1 {main} thrown in /in/Y9aPg on line 6
Process exited with code 255.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Warning: A non-numeric value encountered in /in/Y9aPg on line 6 Notice: A non well formed numeric value encountered in /in/Y9aPg on line 6 Warning: A non-numeric value encountered in /in/Y9aPg on line 6 Notice: A non well formed numeric value encountered in /in/Y9aPg on line 6 Notice: A non well formed numeric value encountered in /in/Y9aPg on line 6 H: 1 E: 0 User 'user1' has password 'phplol'? no Warning: A non-numeric value encountered in /in/Y9aPg on line 6 H: 0 E: 0 User 'user1' has password 'password1'? yes Notice: A non well formed numeric value encountered in /in/Y9aPg on line 6 H: 1 E: 6 User 'user2' has password 'phplol'? no Notice: A non well formed numeric value encountered in /in/Y9aPg on line 6 H: 6 E: 6 User 'user2' has password 'hunter2'? yes Notice: A non well formed numeric value encountered in /in/Y9aPg on line 6 H: 1 E: 0 User 'user3' has password 'phplol'? no Warning: A non-numeric value encountered in /in/Y9aPg on line 6 H: 0 E: 0 User 'user3' has password 'FN4A_zKEe]33p!'? yes Notice: A non well formed numeric value encountered in /in/Y9aPg on line 6 H: 1 E: 251308 User 'user4' has password 'phplol'? no Notice: A non well formed numeric value encountered in /in/Y9aPg on line 6 H: 251308 E: 251308 User 'user4' has password 'xXgjan3a58qzX3'? yes Now let's get funky! Warning: A non-numeric value encountered in /in/Y9aPg on line 6 H: 0 E: 0 User 'user3' has password 'password1'? yes Warning: A non-numeric value encountered in /in/Y9aPg on line 6 H: 0 E: 0 User 'user3' has password 'fN.4A_zKEe]33p!'? yes Warning: A non-numeric value encountered in /in/Y9aPg on line 6 H: 0 E: 0 User 'user3' has password 'fN.4A_zKEe]33p!'? yes
Output for 7.3.32 - 7.3.33
Warning: A non-numeric value encountered in /in/Y9aPg on line 6 Warning: A non-numeric value encountered in /in/Y9aPg on line 6 H: 1 E: 0 User 'user1' has password 'phplol'? no Warning: A non-numeric value encountered in /in/Y9aPg on line 6 H: 0 E: 0 User 'user1' has password 'password1'? yes H: 1 E: 6 User 'user2' has password 'phplol'? no H: 6 E: 6 User 'user2' has password 'hunter2'? yes H: 1 E: 0 User 'user3' has password 'phplol'? no Warning: A non-numeric value encountered in /in/Y9aPg on line 6 H: 0 E: 0 User 'user3' has password 'FN4A_zKEe]33p!'? yes H: 1 E: 251308 User 'user4' has password 'phplol'? no H: 251308 E: 251308 User 'user4' has password 'xXgjan3a58qzX3'? yes Now let's get funky! Warning: A non-numeric value encountered in /in/Y9aPg on line 6 H: 0 E: 0 User 'user3' has password 'password1'? yes Warning: A non-numeric value encountered in /in/Y9aPg on line 6 H: 0 E: 0 User 'user3' has password 'fN.4A_zKEe]33p!'? yes Warning: A non-numeric value encountered in /in/Y9aPg on line 6 H: 0 E: 0 User 'user3' has password 'fN.4A_zKEe]33p!'? yes
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33
H: 1 E: 0 User 'user1' has password 'phplol'? no H: 0 E: 0 User 'user1' has password 'password1'? yes H: 1 E: 6 User 'user2' has password 'phplol'? no H: 6 E: 6 User 'user2' has password 'hunter2'? yes H: 1 E: 0 User 'user3' has password 'phplol'? no H: 0 E: 0 User 'user3' has password 'FN4A_zKEe]33p!'? yes H: 1 E: 251308 User 'user4' has password 'phplol'? no H: 251308 E: 251308 User 'user4' has password 'xXgjan3a58qzX3'? yes Now let's get funky! H: 0 E: 0 User 'user3' has password 'password1'? yes H: 0 E: 0 User 'user3' has password 'fN.4A_zKEe]33p!'? yes H: 0 E: 0 User 'user3' has password 'fN.4A_zKEe]33p!'? yes

preferences:
245.84 ms | 403 KiB | 368 Q