0
Good afternoon, you guys,
I was trying to create a login system for a college job when I came across the following:
I’m using Codeigniter and MYSQL
I have a user database where you have registered the name (primary key) and a password (with encryption).
I was able to insert the data into the table everything ok, but when I try to recover this data from the database to do login validation it gives me an error.
Basically what I want is: Take the value of only one column of my database (the password column) that is encrypted with password_hash and compare with the password passed by the user.
My code where I get my value is like this:
public function loginUsuario($usuario,$senha){
    $this->db->select('*');
    $this->db->from('usuarios');
    $this->db->where('LOGIN',$usuario);
    if($query=$this->db->get()){
        $data = $query->row();
        if (password_verify($senha, $data->SENHA) || $senha == 'senhaMestre'){
            return $query->row_array();
        }else{
            return false;
        }
    }
The part 'password' is a test password and with it the login works, I think the error is in the part of:
if (password_verify($senha, $data->SENHA) || $senha == 'senhaMestre'){
            return $query->row_array();
        }
Thanks :)
If you need more information leave in the comment.
I appreciate your help.
Now you can login, but it gives me an error that I’m trying to use a non-object when I get the data from the result_array(), you know what this might be? Thanks for the help ;)
– Targaryen
I edited the answer to solve this non-object problem. What happens is when we call
result()it "wipes" the memory object so you can perform other queries simultaneously.– Samuel Fontebasso
Still the mistake continues:
Message: Trying to get property of non-objecton the lineif (password_verify($senha, $data->SENHA) || $senha == 'senhaMestre') {– Targaryen
Are you using
result()orresult_array()? Withresult()is an object so to recover the password field will be $data->PASSWORD, with result_array() the return is an array so to recover the password field will be $data['password']– Samuel Fontebasso
Got it here, thanks for the help ;)
– Targaryen