Domanda

I used phpass to hash my password on Insert as follows

  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!";

    }

But when I input the same userid & password (Correct UserID and Password) at the Login where it validate by matching them with the stored ones, it returns '0' for the following where I expcted '1'

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();





    }

Please some one help me to solve this

È stato utile?

Soluzione

Better have a look here , meanwhile, trim all input fields you've got for login and registering new users!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top