Codeigniter无法将散列密码保存到数据库

时间:2014-06-19 07:44:58

标签: mysql codeigniter passwords

我无法将哈希密码保存到我的'用户'表,但如果没有哈希,则保存密码。大家可以帮助我吗?

控制器

public function add()
{
    $this->data['title'] = 'add new user';
    $this->data['subview'] = 'admin/user/add';      

    $validate = $this->user->validate;
    $this->form_validation->set_rules($validate);

    if ($this->form_validation->run() == TRUE){
        $this->user->insert(array(
            'name'          =>  $this->input->post('name'),
            'email'         =>  $this->input->post('email'),
            'password'      =>  $this->user->hash($this->input->post('password'))
        ));

        $this->session->set_flashdata('message', msg_success('Data Saved'));
        redirect('admin/user', 'refresh');
    }

    $this->load->view('admin/_layout_main', $this->data);
}

我在user_model中的哈希函数

public function hash($string)
{
    return hash('md5', $string . config_item('encryption_key'));
}

我的代码有什么问题,或者在没有任何库的情况下还有其他方法吗?或者你是如何使用codeigniter基本上做到这一点的?感谢

修改

这是来自MY_Model的插入功能

public function insert($data, $skip_validation = FALSE)
{
    if ($skip_validation === FALSE)
    {
        $data = $this->validate($data);
    }

    if ($data !== FALSE)
    {
        $data = $this->trigger('before_create', $data);

        $this->_database->insert($this->_table, $data);
        $insert_id = $this->_database->insert_id();

        $this->trigger('after_create', $insert_id);

        return $insert_id;
    }
    else
    {
        return FALSE;
    }
}

我使用Jamie Rumbelow Base Model作为我的基础模型,我已经按照他的教程插入数据库

0 个答案:

没有答案