phpass匹配输入密码和存储密码

时间:2014-01-30 07:46:43

标签: mysql codeigniter phpass

我使用phpass在Insert上散列我的密码,如下所示

  public function addAdmin(){
        $this->load->library('phpass');
        $this->load->database();
        $psw = 'admin1234';
        $hashed = $this->phpass->hash($psw);
        $now = date("Y-m-d H:i:s");

        $data = array(
   'userid' => 'admin_user' ,
   'userfname' => 'Admin' ,
   'userlname' => 'Admin',
   'userdname' => 'Admin' ,
   'useraddress' => '20/72,Vidarshana Mawatha, Galawilawatta, Homagama' ,
   'usercountry' => 'Sri Lanka',
   'usercontactno' => '0112-892199' ,
   'userlastlog' => $now ,
   'userpassword' => $hashed ,
   'userpermission' => '1',
   'useremail' => 'dilukshanmahendra@gmail.com'
);

$this->db->insert('ecom-user', $data); 

        echo "Successfully Added!";

    }

但是当我输入相同的用户ID和密码(正确的用户名和密码)在登录验证时通过将它们与存储的密码进行匹配,对于以下我所指示的“1”

,它返回“0”
public function validateLogin($userid,$userpass){    


    $this->load->library('phpass');
    $this->load->database();
    $hashed = $this->phpass->hash($userpass);

    $this->db->select('*');
    $this->db->from('ecom-user');
    $this->db->where('userid', $userid);
    $this->db->where('userpassword', $hashed);

    $result = $this->db->get();

    echo $this->db->last_query(); 
    echo '<br/>'.$result->num_rows();





    }

请有人帮我解决这个问题

1 个答案:

答案 0 :(得分:0)

最好看看here 同时,修剪您登录和注册新用户的所有输入字段!