[eluser]chiste[/eluser]
Hi
I'll like to store my users emails encrypted (with the ability to uncrypt it later) and check for uniqueness if the user tries to register twice with the same email. The problem is that every time I use the encrypt class I got a different string so it is registered twice in my DB. Maybe I'm doing something wrong.
My Controller
Code:
public function signup() {
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|callback_check_email');
if($this->form_validation->run() === FALSE) {
$this->signup();
} else {
$this->load->model('user_model');
if($this->user_model->signup()){
$this->success();
} else {
$this->signup();
}
}
}
public function check_email($str) {
$this->db->where('email', $this->encrypt->encode($str));
$query = $this->db->get('users');
if ($query->num_rows == 0) {
return TRUE;
} else {
$this->form_validation->set_message('check_email', 'All ready registered.');
return FALSE;
}
}
My Model
Code:
function signup() {
$email = $this->input->post('email');
$name = $this->input->post('name');
$data = array(
'email' => $this->encrypt->encode($email),
'name' => $name,
);
if ($this->db->insert('users', $data)) {
return TRUE;
} else {
return FALSE;
}
}