【问题标题】:How to select and decode column value in codeigniter query如何在codeigniter查询中选择和解码列值
【发布时间】:2015-06-01 01:59:14
【问题描述】:

我有一个用户表,其中密码列的数据使用 Codeigniter 中的加密库进行编码。现在,我想选择编码列进行解码并与密码的用户输入(登录验证)进行比较。这是代码。 我插入了这样的值:

$this->db->insert("my_table",Array("username"=>$this->input->post("username"),"password"=>$this->encrypt->encode($this->input->post("password"))));

现在我以这种方式验证输入:

 $data = $this->db->get("mytable");
    foreach($data as $d){
     if($d["username"] == $this->input->post("username") && $d["password"] == $this->encrypt->decode($this->input->post("password")){
    //success
    break;
    }
}

这对我来说很好用,但是我想要一种更短更简洁的方法来做到这一点。你也知道,对于未来的编码实践。 这是我到目前为止所做的:

$this->db->get_where("my_table",Array($this->encrypt->decode("password")=>$this->input->post("password")));

但是是的!这将返回一条错误消息。错误说:

Unknown column '0' on where clause

【问题讨论】:

  • 你得到的错误是什么。也发布那个错误..
  • 刚刚更新了问题

标签: php codeigniter


【解决方案1】:

问题是您将解码密码设置为数据库列。

Array($this->encrypt->decode("password")=>$this->input->post("password"))

你需要做的更像是:

Array("password" => $this->encrypt->decode("password"))

【讨论】:

    【解决方案2】:

    首先,如果可以解密,加密密码不是一个好主意!!!

    最好的做法是加密输入,然后在数据库中选择

    $this->db->select('*')
    $yhis->db->from('mytable')
    $this->db->where('username', $this->input->post("username"));
    $this->db->where('password', $this->encrypt->encode($this->input->post("password")));
    $this->db->get();
    

    如果结果...登录

    【讨论】:

      猜你喜欢
      • 2017-06-22
      • 2016-05-19
      • 1970-01-01
      • 2021-10-01
      • 2011-09-18
      • 2015-10-06
      • 2016-09-14
      • 2015-02-02
      • 2023-03-17
      相关资源
      最近更新 更多