密码未在codeigniter中加密

时间:2016-01-11 11:55:24

标签: php codeigniter password-encryption

我在控制器文件中有这个代码:

viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
           navigationView.getMenu().getItem(0).setChecked(true); // where 0,1,2.. etc. are the indexes/positions for your menu items
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
});

我在我的模型文件中有这个代码:

       $data = array(
                    'username' => $this->input->post('txt_username'),
                    'password'=>$this->input->post('txt_password')
     );

            $encriptKey = 'super-secret-key';
            $encrypted_string = $this->encrypt->encode($password, $encriptKey);

               if ($this->account_model->insertUser($data,$encrypted_string))
             { 
                $this->session->set_flashdata('msg','successfully registered!');
}

密码未加密。我已初始化加密类。来到这里!!

2 个答案:

答案 0 :(得分:1)

但是为什么要在数据阵列中保存普通的POST密码?我假设你想在你的数据库中插入一个加密的密码,然后尝试类似的东西:

$data = array(
                'username' => $this->input->post('txt_username'),
                'password'=>$this->encrypt->encode($password, $encriptKey);
 );

现在您可以插入$ data,并且您有一个加密密码

答案 1 :(得分:0)

您尚未将加密密码放入$data数组中。

据我所知db->插入只接受2个参数,表和$ data数组

因此,请尝试将加密密码放入$ data数组

$encriptKey = 'super-secret-key';

$data = array('username' => $this->input->post('txt_username'),
              'password' => $this->encrypt->encode($this->input->post('txt_password'), $encriptKey)
             );

if ($this->account_model->insertUser($data)) { 
    $this->session->set_flashdata('msg','successfully registered!');
}

并且

function insertUser($data)
{
    return $this->db->insert('user', $data);
}