mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-12-04 06:05:29 +01:00
36 lines
838 B
PHP
36 lines
838 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Models\Traits;
|
||
|
|
||
|
use App\Facades\Settings;
|
||
|
use Illuminate\Support\Facades\Crypt;
|
||
|
|
||
|
trait CanEncryptField
|
||
|
{
|
||
|
/**
|
||
|
* Returns an acceptable value
|
||
|
*/
|
||
|
private function decryptOrReturn(mixed $value) : mixed
|
||
|
{
|
||
|
// Decipher when needed
|
||
|
if (Settings::get('useEncryption') && $value) {
|
||
|
try {
|
||
|
return Crypt::decryptString($value);
|
||
|
} catch (\Exception $ex) {
|
||
|
return __('errors.indecipherable');
|
||
|
}
|
||
|
} else {
|
||
|
return $value;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Encrypt a value
|
||
|
*/
|
||
|
private function encryptOrReturn(mixed $value) : mixed
|
||
|
{
|
||
|
// should be replaced by laravel 8 attribute encryption casting
|
||
|
return Settings::get('useEncryption') ? Crypt::encryptString($value) : $value;
|
||
|
}
|
||
|
}
|