Add 'Bcrypt' password algorithm
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 29 Sep 2020 08:35:46 +0000 (10:35 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 29 Sep 2020 09:53:32 +0000 (11:53 +0200)
wcfsetup/install/files/lib/system/user/authentication/password/algorithm/Bcrypt.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/system/user/authentication/password/algorithm/Bcrypt.class.php b/wcfsetup/install/files/lib/system/user/authentication/password/algorithm/Bcrypt.class.php
new file mode 100644 (file)
index 0000000..3aa2ee1
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+namespace wcf\system\user\authentication\password\algorithm;
+use wcf\system\user\authentication\password\IPasswordAlgorithm;
+
+/**
+ * Implementation of BCrypt.
+ * 
+ * @author     Tim Duesterhus
+ * @copyright  2001-2020 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package    WoltLabSuite\Core\System\User\Authentication\Password\Algorithm
+ * @since      5.4
+ */
+final class Bcrypt implements IPasswordAlgorithm {
+       private const OPTIONS = [
+               'cost' => 10,
+       ];
+       
+       /**
+        * @inheritDoc
+        */
+       public function verify(string $password, string $hash): bool {
+               return \password_verify($password, $hash);
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function hash(string $password): string {
+               return \password_hash($password, \PASSWORD_BCRYPT, self::OPTIONS);
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function needs_rehash(string $hash): bool {
+               return \password_needs_rehash($hash, \PASSWORD_BCRYPT, self::OPTIONS);
+       }
+}