diff options
-rw-r--r-- | lib/password.php | 21 | ||||
-rw-r--r-- | version-test.php | 6 |
2 files changed, 22 insertions, 5 deletions
diff --git a/lib/password.php b/lib/password.php index e8ec028..e69bc17 100644 --- a/lib/password.php +++ b/lib/password.php @@ -274,6 +274,25 @@ namespace PasswordCompat\binary { return mb_substr($binary_string, $start, $length, '8bit'); } return substr($binary_string, $start, $length); - } + } + + /** + * Check if current PHP version is compatible with the library + * + * @return boolean the check result + */ + function check() { + static $pass = NULL; + if (is_null($pass)) { + if (function_exists('crypt')) { + $hash = '$2y$04$usesomesillystringfore7hnbRJHxXVLeakoG8K30oukPsA.ztMG'; + $test = crypt("password", $hash); + $pass = $test == $hash; + } else { + $pass = false; + } + } + return $pass; + } } diff --git a/version-test.php b/version-test.php index f527e30..96f60ca 100644 --- a/version-test.php +++ b/version-test.php @@ -1,8 +1,6 @@ <?php -$hash = '$2y$04$usesomesillystringfore7hnbRJHxXVLeakoG8K30oukPsA.ztMG'; -$test = crypt("password", $hash); -$pass = $test == $hash; +require "lib/password.php"; -echo "Test for functionality of compat library: " . ($pass ? "Pass" : "Fail"); +echo "Test for functionality of compat library: " . (PasswordCompat\binary\check() ? "Pass" : "Fail"); echo "\n";
\ No newline at end of file |