]> BookStack Code Mirror - bookstack/blobdiff - app/Auth/Access/Mfa/MfaValue.php
Added TOTP verification upon access
[bookstack] / app / Auth / Access / Mfa / MfaValue.php
index 9f9ab29a5012d0fa2eb5b4d2a1c8cf84f673ac9b..ec0d5d563fea7b49b60aaa7cc4ff8e99f4e0e665 100644 (file)
@@ -44,10 +44,24 @@ class MfaValue extends Model
         $mfaVal->save();
     }
 
+    /**
+     * Easily get the decrypted MFA value for the given user and method.
+     */
+    public static function getValueForUser(User $user, string $method): ?string
+    {
+        /** @var MfaValue $mfaVal */
+        $mfaVal = static::query()
+            ->where('user_id', '=', $user->id)
+            ->where('method', '=', $method)
+            ->first();
+
+        return $mfaVal ? $mfaVal->getValue() : null;
+    }
+
     /**
      * Decrypt the value attribute upon access.
      */
-    public function getValue(): string
+    protected function getValue(): string
     {
         return decrypt($this->value);
     }
@@ -55,7 +69,7 @@ class MfaValue extends Model
     /**
      * Encrypt the value attribute upon access.
      */
-    public function setValue($value): void
+    protected function setValue($value): void
     {
         $this->value = encrypt($value);
     }