我有,我可以解密密碼,這樣的代碼:如何將加密應用於任何模型請求?
use ProjectName\Models\Some;
Some::find(1)->pass;
它會自動解密通,這是在我的數據庫加密。 但是,如果我的例子做不同的要求,我的模型:
Some::find(1);
其無法正常工作。請有人能解釋我必須做什麼?
這是全碼:
trait Encryptable
{
public function getAttribute($key)
{
$value = parent::getAttribute($key);
if (in_array($key, $this->encryptable)) {
return Crypt::decrypt($value);
}
return parent::getAttribute($key);
}
public function setAttribute($key, $value)
{
if (in_array($key, $this->encryptable)) {
parent::setAttribute($key, Crypt::encrypt($value));
return;
}
parent::setAttribute($key, $value);
}
}
「我有可以用這種方式解密密碼的代碼:」您可能想閱讀[如何在2016年安全地存儲密碼](https://paragonie.com/blog/2016/02/02/how-safely -store密碼,在-2016)。你不應該加密密碼。 –