From cd64f10a3ca5eeda4e9c6c77bd08c619559d7236 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Wed, 25 Sep 2024 08:39:37 +0200 Subject: [PATCH] Remove useless encryption of the Service field if empty --- app/Models/TwoFAccount.php | 2 +- app/Services/SettingService.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Models/TwoFAccount.php b/app/Models/TwoFAccount.php index 75319b2e..84533e66 100644 --- a/app/Models/TwoFAccount.php +++ b/app/Models/TwoFAccount.php @@ -319,7 +319,7 @@ class TwoFAccount extends Model implements Sortable public function setServiceAttribute($value) { // Encrypt when needed - $this->attributes['service'] = $this->encryptOrReturn($value); + $this->attributes['service'] = $value ? $this->encryptOrReturn($value) : $value; } /** diff --git a/app/Services/SettingService.php b/app/Services/SettingService.php index 58c17802..6244bada 100644 --- a/app/Services/SettingService.php +++ b/app/Services/SettingService.php @@ -210,7 +210,12 @@ class SettingService $twofaccounts->each(function ($item, $key) use (&$success, $encrypted) { try { - $item->service = $encrypted ? Crypt::encryptString($item->service) : Crypt::decryptString($item->service); + // encrypting a null value generate a hash which once decrypted gives an empty string. + // As Service is nullable, we handle it only if the fiel contains a value + if ($item->service) { + $item->service = $encrypted ? Crypt::encryptString($item->service) : Crypt::decryptString($item->service); + } + $item->legacy_uri = $encrypted ? Crypt::encryptString($item->legacy_uri) : Crypt::decryptString($item->legacy_uri); $item->account = $encrypted ? Crypt::encryptString($item->account) : Crypt::decryptString($item->account); $item->secret = $encrypted ? Crypt::encryptString($item->secret) : Crypt::decryptString($item->secret);