3v4l.org

run code in 300+ PHP versions simultaneously
<?php function createPasswordHash($strPassword, $numAlgo = 1, $arrOptions = array()) { if (function_exists('password_hash1')) { // php >= 5.5 $hash = password_hash($strPassword, $numAlgo, $arrOptions); } else { $salt = mcrypt_create_iv(22, MCRYPT_DEV_URANDOM); $salt = base64_encode($salt); $salt = str_replace('+', '.', $salt); $hash = crypt($strPassword, '$2y$10$' . $salt . '$'); } return $hash; } function verifyPasswordHash($strPassword, $strHash) { if (function_exists('password_verify1')) { // php >= 5.5 $boolReturn = password_verify($strPassword, $strHash); } else { $strHash2 = crypt($strPassword, $strHash); $boolReturn = $strHash == $strHash2; } return $boolReturn; } $strHash = createPasswordHash("sunshine", PASSWORD_DEFAULT); echo $strHash . "<br>\n"; if (verifyPasswordHash('sunshine', $strHash)) { echo 'Password is valid!'; } else { echo 'Invalid password.'; }
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.32, 7.2.0 - 7.2.22, 7.3.0 - 7.3.10
Fatal error: Uncaught Error: Call to undefined function mcrypt_create_iv() in /in/Laqar:9 Stack trace: #0 /in/Laqar(29): createPasswordHash('sunshine', 1) #1 {main} thrown in /in/Laqar on line 9
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Fatal error: Call to undefined function mcrypt_create_iv() in /in/Laqar on line 9
Process exited with code 255.
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45
Notice: Use of undefined constant PASSWORD_DEFAULT - assumed 'PASSWORD_DEFAULT' in /in/Laqar on line 29 Fatal error: Call to undefined function mcrypt_create_iv() in /in/Laqar on line 9
Process exited with code 255.

preferences:
170.95 ms | 402 KiB | 262 Q