php - 在 Laravel 中,无法重置加密的用户密码
问题描述
我想加密用户表中的电子邮件地址以保护个人信息。我试过这种方式
应用 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);
}
}
应用\用户.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',];
}
应用程序/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);
}
}
我可以加密电子邮件地址。但我无法登录和重置密码。用户可以在同一个电子邮件地址中创建多个帐户。这是一个非常糟糕的错误。
帮我!!
不同的帐户发送相同的问题,因为我无法登录。我试图重置密码,但失败了。对不起。
解决方案
推荐阅读
- python - 如何在 python 代码中使用重构方法和函数?
- docker - 在 Api net core 中如何使用 docker 引用卷和环境变量
- streamlit - Streamlit:禁用对没有 .py 扩展名的运行文件的防护?
- python - 搜索列表项是否在表中
- java - 将文件上传到 AWS S3 并授予公共访问权限
- python - 从 lightkurve 导入 search_targetpixelfile 会导致分段错误/内核崩溃
- javascript - 具有多种收音机和文本输入类型的 Javascript 测验
- c# - 如何在 C# 中实现关于方法的简短描述?
- c# - 尝试查看数据时出现数据库错误
- java - 传输和保存 MultipartFile 实例