I want to encrypt email address in user table in order to protect personal information. I tried 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',];
}
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);
}
}
I can encrypt email address. But I can't login and reset password. User can make many accounts in same email address. It is very bad bug.
Help ME!!
different accounts send same question because I can't login. I tried to reset password but It failed. Im sorry.