我过去通过以下代码验证我的注册表单:
$this->form_validation->set_rules('password', 'Password', 'trim|required|matches[cpassword]|md5');
$this->form_validation->set_rules('cpassword', 'Confirm Password', 'trim|required');
但是当我浏览我的表单时,它会向我显示密码不匹配的错误。 codeigniter form result
答案 0 :(得分:1)
控制器不适用于数据库。所以,请将您的代码更改为:
$this->form_validation->set_rules('password', 'Password', 'trim|required');
$this->form_validation->set_rules('cpassword', 'Confirm Password', 'trim|required|matches[password]');
如果要将其作为哈希值放入数据库,则应使用模型。这是一个示例代码:
public function signup() {
$password = $this->input->post('password', true);
$hash = password_hash($password, PASSWORD_BCRYPT); // put $hash variable into your database
...
}