Remove useless encryption of the Service field if empty

This commit is contained in:
Bubka 2024-09-25 08:39:37 +02:00
parent 30125e6658
commit cd64f10a3c
2 changed files with 7 additions and 2 deletions

View File

@ -319,7 +319,7 @@ class TwoFAccount extends Model implements Sortable
public function setServiceAttribute($value) public function setServiceAttribute($value)
{ {
// Encrypt when needed // Encrypt when needed
$this->attributes['service'] = $this->encryptOrReturn($value); $this->attributes['service'] = $value ? $this->encryptOrReturn($value) : $value;
} }
/** /**

View File

@ -210,7 +210,12 @@ class SettingService
$twofaccounts->each(function ($item, $key) use (&$success, $encrypted) { $twofaccounts->each(function ($item, $key) use (&$success, $encrypted) {
try { try {
// 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->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->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->account = $encrypted ? Crypt::encryptString($item->account) : Crypt::decryptString($item->account);
$item->secret = $encrypted ? Crypt::encryptString($item->secret) : Crypt::decryptString($item->secret); $item->secret = $encrypted ? Crypt::encryptString($item->secret) : Crypt::decryptString($item->secret);