Php 如何在CodeIgniter中编写用于数据库查询的复合语句
为了设计密码用户名身份验证,我尝试从表(成员资格)中检索“salt”,并将其附加到密码中。然后用SHA256对组合进行加密。但是当我像下面那样编写validate()函数时,出现了一个错误 严重程度:4096 消息:无法将类CI\u DB\u mysql\u驱动程序的对象转换为 串 代码:Php 如何在CodeIgniter中编写用于数据库查询的复合语句,php,database,codeigniter,Php,Database,Codeigniter,为了设计密码用户名身份验证,我尝试从表(成员资格)中检索“salt”,并将其附加到密码中。然后用SHA256对组合进行加密。但是当我像下面那样编写validate()函数时,出现了一个错误 严重程度:4096 消息:无法将类CI\u DB\u mysql\u驱动程序的对象转换为 串 代码: 如何解决这个问题?我正在使用codeigniter 2.1.2。非常感谢 您需要创建两个独立的查询: public function validate(){ $this->db->sel
如何解决这个问题?我正在使用codeigniter 2.1.2。非常感谢 您需要创建两个独立的查询:
public function validate(){
$this->db->select('salt');
$this->db->where('username', $this->input->post('username', TRUE));
$salt = (string) $this->db->get('membership')->row()->salt;
$this->db->where('password',
hash('sha256', $this->input->post('password', TRUE). $salt));
$query=$this->db->get('membership');
if($query->num_rows()==1) {
return TRUE;
}
return FALSE;
}
这不能用MySQL的散列来完成吗?i、 e.
$this->db->where('Password','SHA2(concat('.$this->db->escape('this->db->post('Password',true)),'salt),256',空)代码>?
public function validate(){
$this->db->select('salt');
$this->db->where('username', $this->input->post('username', TRUE));
$salt = (string) $this->db->get('membership')->row()->salt;
$this->db->where('password',
hash('sha256', $this->input->post('password', TRUE). $salt));
$query=$this->db->get('membership');
if($query->num_rows()==1) {
return TRUE;
}
return FALSE;
}