我希望能够使用codeigniter db escape,因为它会使我的密码哈希,但在密码行中,它会在两侧添加两个引号示例'demo1234'
我的盐行没有显示它只是密码。在密码上如何使用我的数据库转义但没有在数据库中的密码行显示引号。
public function addUserToDatabase() {
$this->load->helper('date');
$username = $this->input->post('username');
$email = $this->input->post('email');
$password = $this->input->post('password');
$this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)); // Works OK
// Salt does not work if don't use db escape.
$password = $this->db->escape(sha1($salt . sha1($salt . sha1($password)))); // 'demo1234' shows quotes either side off password
$data = array(
'user_id' => "1",
'user_group_id' => "1",
'username' => $username,
'email' => $email,
'salt' => $salt,
'password' => $password,
'ip' => $this->input->ip_address(),
'status' => "1",
'date_added' => mdate('%Y-%m-%d %H:%i:%s', now())
);
$this->db->insert('user', $data);
}
答案 0 :(得分:0)
我解决了这个问题,我必须像下面这样做,一切都完成了。
public function addUserToDatabase() {
$this->load->helper('date');
$username = $this->input->post('username');
$email = $this->input->post('email');
$this->db->escape($password = sha1($salt . sha1($salt . sha1($this->input->post('password')))));
$this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9));
$data = array(
'user_id' => "1",
'user_group_id' => "1",
'username' => $username,
'email' => $email,
'salt' => $salt,
'password' => $password,
'ip' => $this->input->ip_address(),
'status' => "1",
'date_added' => mdate('%Y-%m-%d %H:%i:%s', now())
);
$this->db->insert('user', $data);
}