Welcome Guest, Not a member yet? Register   Sign In
[Solved] Change password function
#1

[eluser]markanderson993[/eluser]
I am trying to write a script to allow the user to change their password. I have all of the required code down (check if certain fields are filled in yatta yatta). The part I am having grief over is checking weather or not the user's inputted current password matches that of their real current password in the database.

This is what I have. This code is the problematic portion. It is supposed to send back a TRUE/FALSE value depending on weather it found a match.

Problem is: I'm getting two errors
1. Undefined property: CI_DB_mysql_result::$hash
3. Undefined property: CI_DB_mysql_result::$password

Code:
//* check_password
        
        public function check_password($users, $current_password)
        {
            $username = $this->ci->session->userdata('username');
            $result = $this->ci->db->select('password','hash')->from($users)->where($users.'.username', $username)->get();
            $password = sha1($this->salt.$result->hash.$current_password); # New hashed password
            if ($password === $result->password)
            {
                return true;
            }
        
        }
#2

[eluser]mironcho[/eluser]
Try this:
Code:
public function check_password($users, $current_password)
{
    $username = $this->ci->session->userdata('username');
    $query = $this->ci->db->select('password, hash')->from($users)->where('username', $username)->get();
    if ($query->num_rows() > 0)
    {
        $result = $query->row();
        $password = sha1($this->salt . $result->hash . $current_password); # New hashed password
        if ($password === $result->password)
        {
            return true;
        }
    }
    return false;
}
Should work, haven't tested it though.
#3

[eluser]markanderson993[/eluser]
Works like a charm, thanks a bunch Mironcho Smile




Theme © iAndrew 2016 - Forum software by © MyBB