dounuogong0358 2012-12-29 21:42
浏览 50
已采纳

登录时如何将注册用户的加密密码作为普通密码接受? [关闭]

I recently created a register page where a user can sign up and create their own account. But say if I log out and then go back into the account and try logging in only the encrypted version of the password is accepted. How can I make my loguserin function talk to my database and have it understand that it's actually a normal password the user orignally entered?

Controller:

 function loguserin()
 {

$this->load->helper(array('form', 'url'));

$this->load->library('form_validation');

$this->form_validation->set_rules('username', 'Username', 'required|min_length[4]|max_length[12]|callback_validateUser|trim');
$this->form_validation->set_rules('password', 'Password', 'required|md5|trim');


if ($this->form_validation->run())
{
    $username = $this->input->post('username');
    $password = $this->input->post('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/logintitle');
    $this->load->view('account/loginview');
    $this->load->view('shared/footer');
}
 }



  function validateUser($username, $password)
  {
    $this->db->select('*')->from('membership');
    $this->db->where('username', $username);
    $this->db->where('password',MD5($password));
    $query = $this->db->get();
    if ($query ->num_rows ==1)
    {
    $this->form_validation->set_message('validateUser', 'Invalid username/password');

    return false;
}

else{

    return true;

}
}
  • 写回答

3条回答 默认 最新

  • dongtao9887 2012-12-29 21:56
    关注

    Depending upon what hashing you are using to store the password, your model confitions would be something like this:

    $this->db->select('*')->from('membership');
    $this->db->where('username', $username);
    $this->db->where('password', MD5($password));
    

    Also, there is a bug in your model for checking if a user is valid. If number of rows returned from DB is 1, then the user is valid, otherwise not.

    if ($query->num_rows == 1)
        {
            return true;
        }
    
    else
    {
        $this->form_validation->set_message('validateUser', 'Invalid username/password');
        return false;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么