php - How to select and decode column value in codeigniter query -
i have table users data password column encoded using encrypt library in codeigniter. now, want select encoded column decode , compare password's user input (login validation). here's code. inserted value this:
$this->db->insert("my_table",array("username"=>$this->input->post("username"),"password"=>$this->encrypt->encode($this->input->post("password"))));
for validate input way:
$data = $this->db->get("mytable"); foreach($data $d){ if($d["username"] == $this->input->post("username") && $d["password"] == $this->encrypt->decode($this->input->post("password")){ //success break; } }
this works fine me but, want shorter , cleaner way this. know, also, future coding practice. here's have done far:
$this->db->get_where("my_table",array($this->encrypt->decode("password")=>$this->input->post("password")));
but yeah! returns error message. error says:
unknown column '0' on clause
the problem setting decoded password database column.
array($this->encrypt->decode("password")=>$this->input->post("password"))
what need doing more like:
array("password" => $this->encrypt->decode("password"))
Comments
Post a Comment