繁体   English   中英

如何使用 Codeigniter 从数据库中解密加密密码

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM