3v4l.org

run code in 300+ PHP versions simultaneously
<?php # # Portable PHP password hashing framework. # # Version 0.3 / genuine. # # Written by Solar Designer <solar at openwall.com> in 2004-2006 and placed in # the public domain. Revised in subsequent years, still public domain. # # There's absolutely no warranty. # # The homepage URL for this framework is: # # http://www.openwall.com/phpass/ # # Please be sure to update the Version line if you edit this file in any way. # It is suggested that you leave the main version number intact, but indicate # your project name (after the slash) and add your own revision information. # # Please do not change the "private" password hashing method implemented in # here, thereby making your hashes incompatible. However, if you must, please # change the hash type identifier (the "$P$") to something different. # # Obviously, since this code is in the public domain, the above are not # requirements (there can be none), but merely suggestions. # class PasswordHash { var $itoa64; var $iteration_count_log2; var $portable_hashes; var $random_state; function PasswordHash($iteration_count_log2, $portable_hashes) { $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) $iteration_count_log2 = 8; $this->iteration_count_log2 = $iteration_count_log2; $this->portable_hashes = $portable_hashes; $this->random_state = microtime(); if (function_exists('getmypid')) $this->random_state .= getmypid(); } function get_random_bytes($count) { $output = ''; if (is_readable('/dev/urandom') && ($fh = @fopen('/dev/urandom', 'rb'))) { $output = fread($fh, $count); fclose($fh); } if (strlen($output) < $count) { $output = ''; for ($i = 0; $i < $count; $i += 16) { $this->random_state = md5(microtime() . $this->random_state); $output .= pack('H*', md5($this->random_state)); } $output = substr($output, 0, $count); } return $output; } function encode64($input, $count) { $output = ''; $i = 0; do { $value = ord($input[$i++]); $output .= $this->itoa64[$value & 0x3f]; if ($i < $count) $value |= ord($input[$i]) << 8; $output .= $this->itoa64[($value >> 6) & 0x3f]; if ($i++ >= $count) break; if ($i < $count) $value |= ord($input[$i]) << 16; $output .= $this->itoa64[($value >> 12) & 0x3f]; if ($i++ >= $count) break; $output .= $this->itoa64[($value >> 18) & 0x3f]; } while ($i < $count); return $output; } function gensalt_private($input) { $output = '$P$'; $output .= $this->itoa64[min($this->iteration_count_log2 + ((PHP_VERSION >= '5') ? 5 : 3), 30)]; $output .= $this->encode64($input, 6); return $output; } function crypt_private($password, $setting) { $output = '*0'; if (substr($setting, 0, 2) == $output) $output = '*1'; $id = substr($setting, 0, 3); # We use "$P$", phpBB3 uses "$H$" for the same thing if ($id != '$P$' && $id != '$H$') return $output; $count_log2 = strpos($this->itoa64, $setting[3]); if ($count_log2 < 7 || $count_log2 > 30) return $output; $count = 1 << $count_log2; $salt = substr($setting, 4, 8); if (strlen($salt) != 8) return $output; # We're kind of forced to use MD5 here since it's the only # cryptographic primitive available in all versions of PHP # currently in use. To implement our own low-level crypto # in PHP would result in much worse performance and # consequently in lower iteration counts and hashes that are # quicker to crack (by non-PHP code). if (PHP_VERSION >= '5') { $hash = md5($salt . $password, TRUE); do { $hash = md5($hash . $password, TRUE); } while (--$count); } else { $hash = pack('H*', md5($salt . $password)); do { $hash = pack('H*', md5($hash . $password)); } while (--$count); } $output = substr($setting, 0, 12); $output .= $this->encode64($hash, 16); return $output; } function gensalt_extended($input) { $count_log2 = min($this->iteration_count_log2 + 8, 24); # This should be odd to not reveal weak DES keys, and the # maximum valid value is (2**24 - 1) which is odd anyway. $count = (1 << $count_log2) - 1; $output = '_'; $output .= $this->itoa64[$count & 0x3f]; $output .= $this->itoa64[($count >> 6) & 0x3f]; $output .= $this->itoa64[($count >> 12) & 0x3f]; $output .= $this->itoa64[($count >> 18) & 0x3f]; $output .= $this->encode64($input, 3); return $output; } function gensalt_blowfish($input) { # This one needs to use a different order of characters and a # different encoding scheme from the one in encode64() above. # We care because the last character in our encoded string will # only represent 2 bits. While two known implementations of # bcrypt will happily accept and correct a salt string which # has the 4 unused bits set to non-zero, we do not want to take # chances and we also do not want to waste an additional byte # of entropy. $itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $output = '$2a$'; $output .= chr(ord('0') + $this->iteration_count_log2 / 10); $output .= chr(ord('0') + $this->iteration_count_log2 % 10); $output .= '$'; $i = 0; do { $c1 = ord($input[$i++]); $output .= $itoa64[$c1 >> 2]; $c1 = ($c1 & 0x03) << 4; if ($i >= 16) { $output .= $itoa64[$c1]; break; } $c2 = ord($input[$i++]); $c1 |= $c2 >> 4; $output .= $itoa64[$c1]; $c1 = ($c2 & 0x0f) << 2; $c2 = ord($input[$i++]); $c1 |= $c2 >> 6; $output .= $itoa64[$c1]; $output .= $itoa64[$c2 & 0x3f]; } while (1); return $output; } function HashPassword($password) { $random = ''; if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) { $random = $this->get_random_bytes(16); $hash = crypt($password, $this->gensalt_blowfish($random)); if (strlen($hash) == 60) return $hash; } if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) { if (strlen($random) < 3) $random = $this->get_random_bytes(3); $hash = crypt($password, $this->gensalt_extended($random)); if (strlen($hash) == 20) return $hash; } if (strlen($random) < 6) $random = $this->get_random_bytes(6); $hash = $this->crypt_private($password, $this->gensalt_private($random)); if (strlen($hash) == 34) return $hash; # Returning '*' on error is safe here, but would _not_ be safe # in a crypt(3)-like function used _both_ for generating new # hashes and for validating passwords against existing hashes. return '*'; } function CheckPassword($password, $stored_hash) { $hash = $this->crypt_private($password, $stored_hash); if ($hash[0] == '*') $hash = crypt($password, $stored_hash); return $hash == $stored_hash; } } ?>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
7.4.00.0070.01315.00
7.3.120.0140.00415.00
7.3.110.0130.00614.56
7.3.100.0040.01114.73
7.3.90.0030.01414.56
7.3.80.0030.01014.79
7.3.70.0000.00914.58
7.3.60.0070.00714.94
7.3.50.0030.00914.48
7.3.40.0060.00314.84
7.3.30.0040.01114.80
7.3.20.0060.00316.28
7.3.10.0040.00716.50
7.3.00.0090.00916.52
7.2.250.0080.01114.63
7.2.240.0030.01614.50
7.2.230.0080.00414.93
7.2.220.0110.00314.98
7.2.210.0070.01014.57
7.2.200.0040.00714.97
7.2.190.0030.01114.90
7.2.180.0040.00814.86
7.2.170.0060.00315.04
7.2.00.0100.00319.04
7.1.330.0040.01415.47
7.1.320.0100.00315.43
7.1.310.0070.00715.63
7.1.300.0080.00415.48
7.1.290.0000.01315.61
7.1.280.0000.01415.57
7.1.270.0070.00715.55
7.1.260.0060.00615.60
7.1.70.0000.00716.94
7.1.60.0070.01819.46
7.1.50.0100.01316.95
7.1.00.0100.07322.41
7.0.200.0030.00616.55
7.0.140.0070.07021.95
7.0.100.0100.07021.91
7.0.90.0000.05321.67
7.0.80.0030.08021.68
7.0.70.0030.07721.64
7.0.60.0030.08321.79
7.0.50.0170.07022.12
7.0.40.0030.08720.14
7.0.30.0070.08019.96
7.0.20.0070.07720.06
7.0.10.0100.07720.04
7.0.00.0030.05319.98
5.6.280.0170.05721.18
5.6.250.0070.08020.60
5.6.240.0000.04320.63
5.6.230.0130.07320.69
5.6.220.0000.07320.65
5.6.210.0030.08320.65
5.6.200.0000.05320.95
5.6.190.0100.07021.12
5.6.180.0000.08321.06
5.6.170.0030.07320.96
5.6.160.0000.08021.18
5.6.150.0030.08321.09
5.6.140.0030.07021.04
5.6.130.0130.07721.09
5.6.120.0130.05721.12
5.6.110.0070.08321.09
5.6.100.0070.06720.97
5.6.90.0030.08721.02
5.6.80.0030.07720.41
5.6.70.0030.08020.55
5.6.60.0000.08020.40
5.6.50.0070.07320.41
5.6.40.0070.04720.50
5.6.30.0030.07720.42
5.6.20.0030.08020.43
5.6.10.0130.06720.44
5.6.00.0070.07320.43
5.5.380.0030.08320.57
5.5.370.0000.04320.50
5.5.360.0070.08020.41
5.5.350.0000.08020.33
5.5.340.0100.07320.90
5.5.330.0100.07720.91
5.5.320.0000.07320.93
5.5.310.0030.08320.64
5.5.300.0030.08320.76
5.5.290.0130.07320.78
5.5.280.0100.07320.78
5.5.270.0070.05020.64
5.5.260.0100.07320.77
5.5.250.0030.08020.66
5.5.240.0070.07020.31
5.5.230.0070.07720.31
5.5.220.0000.08020.22
5.5.210.0000.07720.30
5.5.200.0100.07020.27
5.5.190.0070.07320.16
5.5.180.0030.08320.26
5.5.160.0000.07020.24
5.5.150.0070.08020.24
5.5.140.0030.07720.22
5.5.130.0030.07720.18
5.5.120.0000.07020.27
5.5.110.0030.06320.18
5.5.100.0100.06319.96
5.5.90.0070.07320.18
5.5.80.0070.07319.95
5.5.70.0030.07319.94
5.5.60.0000.07720.01
5.5.50.0070.07020.07
5.5.40.0030.07720.03
5.5.30.0030.08020.03
5.5.20.0070.07319.99
5.5.10.0070.06320.14
5.5.00.0030.08020.07
5.4.450.0070.04719.18
5.4.440.0070.07319.21
5.4.430.0100.07719.20
5.4.420.0030.07719.56
5.4.410.0030.08019.32
5.4.400.0000.06019.13
5.4.390.0100.07319.13
5.4.380.0100.04719.21
5.4.370.0070.07718.95
5.4.360.0030.07319.14
5.4.350.0070.07018.90
5.4.340.0070.07718.88
5.4.320.0000.04718.90
5.4.310.0100.07019.18
5.4.300.0030.06019.14
5.4.290.0100.05719.12
5.4.280.0030.07019.14
5.4.270.0100.07019.05
5.4.260.0130.06318.86
5.4.250.0130.05719.04
5.4.240.0100.05719.04
5.4.230.0030.07318.98
5.4.220.0030.07319.03
5.4.210.0030.07019.09
5.4.200.0030.07018.94
5.4.190.0100.07019.13
5.4.180.0030.06718.84
5.4.170.0030.07318.87
5.4.160.0030.07719.21
5.4.150.0070.06019.03
5.4.140.0100.06716.53
5.4.130.0030.05716.42
5.4.120.0000.06316.42
5.4.110.0100.06716.50
5.4.100.0030.07016.56
5.4.90.0000.07716.46
5.4.80.0070.06716.47
5.4.70.0030.07316.50
5.4.60.0000.05716.54
5.4.50.0000.07316.50
5.4.40.0030.06016.41
5.4.30.0070.06716.49
5.4.20.0070.03716.36
5.4.10.0000.07316.56
5.4.00.0100.07015.63
5.3.290.0070.07714.68
5.3.280.0070.07714.68
5.3.270.0030.07314.66
5.3.260.0070.07014.63
5.3.250.0070.07014.73
5.3.240.0100.05714.61
5.3.230.0030.05014.62
5.3.220.0070.07014.64
5.3.210.0030.07714.66
5.3.200.0130.06714.73
5.3.190.0100.07014.57
5.3.180.0070.07014.77
5.3.170.0100.07014.74
5.3.160.0070.07314.62
5.3.150.0000.08014.75
5.3.140.0100.07714.71
5.3.130.0030.07314.63
5.3.120.0030.07714.50
5.3.110.0000.07714.62
5.3.100.0030.07014.14
5.3.90.0070.04314.20
5.3.80.0000.07314.10
5.3.70.0070.07014.15
5.3.60.0030.07714.06
5.3.50.0130.06013.94
5.3.40.0000.05713.93
5.3.30.0070.07014.05
5.3.20.0030.07313.87
5.3.10.0000.06013.86
5.3.00.0000.08013.77

preferences:
28.77 ms | 400 KiB | 5 Q