laravel-aescrypt icon indicating copy to clipboard operation
laravel-aescrypt copied to clipboard

Nothing happended

Open Kingmaddi opened this issue 6 years ago • 1 comments

Hi,

thank you for this plugin. I have a problem with saving encrypted data. Then i save my model, the normal unencrypted data saved to the database. What´s my mistake? I declare the encryption key in the env-file like you describe it in your introduction.

Thank you for help

Kingmaddi avatar Dec 30 '18 21:12 Kingmaddi

Same issue here on a new Laravel project (5.7.19). It does work when you update your model with a new value.

This seems to be caused by the different handling in the performInsert and performUpdate functions in Illuminate\Database\Eloquent\Model.

The performInsert function uses Model->getAttributes(), which returns the unencrypted values. The performUpdate function uses Model->getDirty(), which returns the encrypted values.

Example:

$ php artisan tinker
Psy Shell v0.9.9 (PHP 7.3.0 — cli) by Justin Hileman
>>> $account=new App\testaccount();
=> App\testaccount {#3005}
>>> $account->username='user1'
=> "user1"
>>> $account->password1='test'
=> "test"
>>> $account->getAttributes();
=> [
     "username" => "user1",
     "password1" => "test",
   ]
>>> $account->getDirty();
=> [
     "username" => "user1",
     "password1" => "__AESCRYPT__:lkoFwYJFVGm3CLjhuKxVqQ==",
   ]
>>>

Currently i've removed the (overridden) function getAttributes() from Aescrypt.php, but i don't know if this has any impact on other things.

RGlintmeijer avatar Jan 07 '19 00:01 RGlintmeijer