3 namespace BookStack\Auth\Access\Mfa;
5 use BookStack\Auth\User;
7 use Illuminate\Database\Eloquent\Model;
11 * @property int $user_id
12 * @property string $method
13 * @property string $value
14 * @property Carbon $created_at
15 * @property Carbon $updated_at
17 class MfaValue extends Model
19 protected static $unguarded = true;
21 const METHOD_TOTP = 'totp';
22 const METHOD_BACKUP_CODES = 'backup_codes';
25 * Upsert a new MFA value for the given user and method
26 * using the provided value.
28 public static function upsertWithValue(User $user, string $method, string $value): void
30 /** @var MfaValue $mfaVal */
31 $mfaVal = static::query()->firstOrNew([
32 'user_id' => $user->id,
35 $mfaVal->setValue($value);
40 * Decrypt the value attribute upon access.
42 public function getValue(): string
44 return decrypt($this->value);
48 * Encrypt the value attribute upon access.
50 public function setValue($value): void
52 $this->value = encrypt($value);