拉拉维尔中的加密密码出错。 "The payload is invalid."



当我创建一个特征以加密数据库中的密码时(出于安全目的(,我尝试使用它时,我会得到:"有效载荷无效。我该如何解决?

trait Encryptable
{
    public function getAttribute($key)
    {
        $value = parent::getAttribute($key);
        if (in_array($key, $this->encryptable, true)) {
            $value = Crypt::decrypt($value);
        }
        return $value;
    }
    public function setAttribute($key, $value)
    {
        if (in_array($key, $this->encryptable, true)) {
            $value = Crypt::encrypt($value);
        }
        return parent::setAttribute($key, $value);
    }
}
class User extends Authenticatable
{
    use Notifiable;
    use Encryptable;
    protected $encryptable = [
        'password',
    ]; 
    protected $fillable = [
        'name', 'email', 'password',
    ];
    protected $hidden = [
        'password', 'remember_token',
    ];
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}

密码被哈希,在laravel中没有加密。这是为了防止将密码倒回数据库(恶意或从开发人员中(。这是一个单向的过程,没有办法将密码撤回和/或将其发送给用户。出于安全目的,您可能希望重新考虑架构以使用哈希而不是加密。

这是一个很好的讨论,基本上说同样的话。

希望这会有所帮助。

相关内容

最新更新