[英]How to Decrypt an Encrypted Password from Database using Codeigniter
我正在嘗試解密存儲在 MySQL Workbench 數據庫中的密碼。 我使用了 codeigniter 的 Encrypt() function。 它進入數據庫就好了。 但是當我嘗試運行此代碼時,出現錯誤:消息:strlen() 期望參數 1 為字符串,object 給定文件名:庫/加密。php 我想將通過表單輸入的密碼與解密后的密碼進行比較數據庫,看看它們是否匹配。 我不知道如何糾正這個問題,我知道這可能是一個非常菜鳥的問題,但我很困惑。 感謝您的任何幫助!
{
$this->db->select("custPassword");
$this->db->from('customer');
$this->db->where('custEmail', $customerEmail);
$passencrypted = $this->db->get();
$passplain = $this->encryption->decrypt($passencrypted);
$this->db->select("custNumber");
$this->db->from('customer');
$this->db->where('custEmail', $customerEmail);
$this->db->where('custPassword', $passplain);
$query = $this->db->get();
$count = $query->num_rows();
if($count == 1)
{
return true;
}
else
{
return false;```
BigDog123 歡迎加入社區。
行中的問題
$passencrypted = $this->db->get();
$passplain = $this->encryption->decrypt($passencrypted);
作為 Codeignitor 文檔$this->db->get()返回數據庫結果 (CI_DB_result) 這是一個 object。 因此,當您將 $passencrypted 傳遞給解密方法時,您傳遞的是 object 而不是字符串。 $this->encryption->decrypt() 接受字符串作為參數。
對於解決方案,您需要使用 CI_DB_result class 中的 result() 或其他方法,在此處了解更多信息
$passencrypted = $this->db->get()->row();
if (isset($passencrypted))
{
$passplain = $this->encryption->decrypt($passencrypted->custPassword);
}
注意:最好將密碼 hash 存儲起來,而不是加密存儲。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.