I want to encrypt email addresses in a user table to protect personal information. I try this way: app¥Encryptable.php
<?php
namespace App;
use Crypt;
trait Encryptable{
public function getAttribute($key){
$value = parent::getAttribute($key);
if (in_array($key, $this->encryptable)) {$value = Crypt::decrypt($value);return $value;}
return $value;
}
public function setAttribute($key, $value){
if (in_array($key, $this->encryptable)) {$value = Crypt::encrypt($value);}
return parent::setAttribute($key, $value);
}
}
app\User.php
<?php
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;
use Illuminate\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use App\Encryptable;
class User extends Authenticatable implements MustVerifyEmailContract{
use MustVerifyEmail, Notifiable;
use Encryptable;
protected $fillable = ['name', 'email', 'password',];
protected $hidden = ['password', 'remember_token',];
protected $casts = [email_verified_at' => 'datetime',];
public $encryptable = [email',];
}
I can encrypt the email address. But I can't log in and reset the password. User can make many accounts in the same email address. It is a very bad bag.
Help ME!!