加密不能在ajax中工作

时间:2016-09-21 10:11:12

标签: ajax codeigniter encryption

我总是在codeigniter中使用加密和解密。现在,当我尝试使用ajax解密登录时,不能为我工作。我的编码如下

<?php
public function CheckLogin(){
        $this->input->post('password');
        $password = $this->encrypt->decode($this->input->post('password'));
        if($this->input->post('profile') == 'distributer'){
                $Response = $this->db->get_where($this->db->dbprefix."distsributer_account",array('username'=>$this->input->post('username'),'password'=>$password,'status'=>'Y'))->result();
        }
        if($this->input->post('profile') == 'retailer'){
                $Response = $this->db->get_where($this->db->dbprefix."Sefnder",array('Username'=>$this->input->post('username'),'Password'=>$password,'status'=>'Y'))->result();
        }
}
?>

当我检查控制台提供错误的表名密码时显示0表示$this->encrypt->decode($this->input->post('password'))对我不起作用。

我已经检查了$ this-&gt; input-&gt; post(&#39;密码&#39;)工作正常的价值

我返回的sql查询是这个

SELECT * FROM `flip_distsributer_account`
WHERE `username` = 'Asht@160921'
AND `password` =0
AND `status` = 'Y'

1 个答案:

答案 0 :(得分:0)

您应该使用用户名搜索并在解密保存的密码后匹配密码。

<?php
public function CheckLogin(){
        $password = $this->input->post('password');
        if($this->input->post('profile') == 'distributer'){
            $Response = $this->db->get_where($this->db->dbprefix."distsributer_account",array('username'=>$this->input->post('username'),'status'=>'Y'))->row_array();
            if($this->encrypt->decode($Response['password']) == $password)           {
            echo "Password is equal";
         }
        }
        if($this->input->post('profile') == 'retailer'){
                $Response = $this->db->get_where($this->db->dbprefix."Sefnder",array('Username'=>$this->input->post('username'),'status'=>'Y'))->result();
        }
}