summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2014-07-28 19:34:43 +0200
committerRemi Collet <fedora@famillecollet.com>2014-07-28 19:34:43 +0200
commit1364db9776b29b5ea7f990671c0832e9aa887e0d (patch)
tree1361462beba950e9880c2d2aff3681fcfb21db84
parentc91b1168bc53c26f56fc65f16958b5be45ca5dc9 (diff)
downloadpassword_compat-1364db9776b29b5ea7f990671c0832e9aa887e0d.zip
password_compat-1364db9776b29b5ea7f990671c0832e9aa887e0d.tar.gz
password_compat-1364db9776b29b5ea7f990671c0832e9aa887e0d.tar.bz2
add PasswordCompat\binary\check() in the library
-rw-r--r--lib/password.php21
-rw-r--r--version-test.php6
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