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 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试