aboutsummaryrefslogtreecommitdiff
path: root/app/Utils/passwordUtil.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Utils/passwordUtil.php')
-rw-r--r--app/Utils/passwordUtil.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/Utils/passwordUtil.php b/app/Utils/passwordUtil.php
new file mode 100644
index 000000000..fd71d4b72
--- /dev/null
+++ b/app/Utils/passwordUtil.php
@@ -0,0 +1,27 @@
+<?php
+
+class FreshRSS_password_Util {
+ // Will also have to be computed client side on mobile devices,
+ // so do not use a too high cost
+ const BCRYPT_COST = 9;
+
+ /**
+ * Return a hash of a plain password, using BCRYPT
+ *
+ * @param string
+ * @return string
+ */
+ public static function hash($passwordPlain) {
+ $passwordHash = password_hash(
+ $passwordPlain,
+ PASSWORD_BCRYPT,
+ array('cost' => self::BCRYPT_COST)
+ );
+ $passwordPlain = '';
+
+ // Compatibility with bcrypt.js
+ $passwordHash = preg_replace('/^\$2[xy]\$/', '\$2a\$', $passwordHash);
+
+ return $passwordHash == '' ? '' : $passwordHash;
+ }
+}