php - 如何使用 Codeigniter 从数据库中解密加密密码
问题描述
我正在尝试解密存储在 MySQL Workbench 数据库中的密码。我使用了 codeigniter 的 Encrypt() 函数。它进入数据库就好了。但是当我尝试运行此代码时,出现错误:消息:strlen() 期望参数 1 为字符串,对象给定文件名:libraries/Encryption.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) 这是一个对象。因此,当您将 $passencrypted 传递给解密方法时,您传递的是对象而不是字符串。$this->encryption->decrypt() 接受字符串作为参数。
对于解决方案,您需要使用 result() 或 CI_DB_result 类中的其他方法,在此处了解更多信息
$passencrypted = $this->db->get()->row();
if (isset($passencrypted))
{
$passplain = $this->encryption->decrypt($passencrypted->custPassword);
}
注意:最好将密码散列并存储,而不是加密并存储。
推荐阅读
- c++ - CMake 不会为简单的测试程序生成 vc pdb
- java - 单击recyclerview中的项目时从列表中删除项目
- google-apps-script - 如何防止触发器多次激活?
- xml - 从字符串(不是文件)获取 XML
- android - 底部工作表布局中存在的 NestedScrollview 中的 BottomSheet 片段滚动行为问题
- reactjs - 使用 reactjs 和 material-ui 更改步进器的活动步进颜色
- python - 从 ARIMA 模型重新调整预测
- java - 什么可以改变Java生成的XML文件中元素属性的顺序?
- reactjs - 我想在我的反应原生应用程序中的图像上添加标题,例如 whatsapp
- node.js - 无法在任何 docker 容器中使用 npm