正在将密码保存到codeigniter中的数据库中


Saving password to the database in codeigniter

我想问如何将用户的密码保存到数据库中?我已经完成了,但保存到数据库的结果与输入的密码不同。和密码,却变成了一个奇怪的代码那么长。尽管我一直在使用动作"md5"。请更正我的语法控制器出了什么问题。感谢

function add(){
    $data['title']="Add user";
    $this->_set_rules();
    if($this->form_validation->run()==true){
        $kode=$this->input->post('username'); 
        $cek=$this->m_user->cek($kode); 
        if($cek->num_rows()>0){
            $data['message']="<div class='alert alert-danger'>Username is already in use/div>";
            $this->template->display('admin/adduser',$data);
        }else{
            $info=array(
                'name'=>$this->input->post('name'),
                'addres'=>$this->input->post('addres'),
                'dateofbirth'=>$this->input->post('dateof birth'),
                'email'=>$this->input->post('email'),
                'username'=>$this->input->post('user'),
                'password'=>md5($this->input->post('password')),
                'level'=>$this->input->post('level')
            );
            $this->m_user->save($info);
            redirect('admin/user/add_success');
        }
    }else{
        $data['message']="";
        $this->template->display('admin/adduser',$data);
    }
}

md5是一种哈希算法,它将您的密码哈希为32个字符长度的字符串。该字符串是您输入的密码的哈希值。例如,如果您的密码是abcd,那么md5(密码)将是d41d8cd98f00b204e9800998ecf8427e。删除该md5()以查看您的密码

如果您将md5应用于通过表单post收到的输入,则意味着您希望以安全格式加密密码。md5()基本上应用加密来生成一个32个字符长的文本,该文本是安全的,不可能解密。

此外,这被认为是遵循此策略的好做法,但在将相同的主题应用于您的需求和数据之前,您需要稍微小心一点。

此外,如果你不想应用这种加密,那么只需在后变量之前省略这种方法:

 Before: 'password'=>md5($this->input->post('password')),//Gives encrypted 32 char long text
 After : 'password'=>($this->input->post('password'),    //Gives plain text