我正在尝试创建新帐户并将每个用户的注册详细信息以加密形式输入我的会员数据库 - 目前可以在数据库中看到实际密码。为什么是这样?我正在使用表单验证库,并且已经包含了密码字段的 md5 规则,但它似乎没有产生任何影响。
控制器:
function register()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required|callback_usernameTaken|min_length[5]|max_length[12]|trim');
$this->form_validation->set_rules('password', 'Password', 'required|md5|trim');
$username = $this->input->post('username');
$password = $this->input->post('password');
if ( $this->form_validation->run()&& !$this->membership->usernameTaken($username)){
$this->membership->newUser($username, $password);
$this->session->set_userdata('status', 'OK');
$this->session->set_userdata('username', $username);
redirect('home');
}
else
{
$this->session->set_userdata('status', 'NOT_OK');
$this->load->view('shared/header');
$this->load->view('account/signuptitle');
$this->load->view('account/signupview');
$this->load->view('shared/footer');
}
}
再次感谢您的帮助
模型:
function newUser($username, $password)
{
$newMember = array ('username' => $username,
'password' => $password);
$insert = $this->db->insert('membership', $newMember);
}
function usernameTaken($username)
{
$this->db->select('*')->from ('membership')->where('username', $username);
$query = $this->db->get();
if ($query->num_rows > 0)
{
echo "<p>";
echo 'username taken';
echo "</p>";
return true;
}
else{
return false;
}
}