[Solved] UserIdentity - Different Column Names

I am trying to follow the example of using a database to authenticate. I am receiving errors because my model (table) has different column names. ie - the columns are not labelled username or password, that are for example "user_name" and "user_password". Can someone tell me where I may be going wrong because i keep receiving an exception telling me my column is undefined


class UserIdentity extends CUserIdentity

{

    private $_id;

    public function authenticate()

    {

        $record=User::model()->findByAttributes(array('username'=>$this->username));

        if($record===null)

            $this->errorCode=self::ERROR_USERNAME_INVALID;

        else if($record->password!==md5($this->password))

            $this->errorCode=self::ERROR_PASSWORD_INVALID;

        else

        {

            $this->_id=$record->id;

            $this->setState('title', $record->title);

            $this->errorCode=self::ERROR_NONE;

        }

        return !$this->errorCode;

    }

 

    public function getId()

    {

        return $this->_id;

    }

}

If your columns are user_name ad user_password… then use that in your code… the code you posted uses “username” and “password”… that’s why you get the error…

It is working now. Thank you for pointing me in the right direction. I changed the obvious pieces of code (highlighted below).


class UserIdentity extends CUserIdentity

{

    private $_id;

    public function authenticate()

    {

        $record=User::model()->findByAttributes(array('user_name'=>$this->username));

        if($record===null)

            $this->errorCode=self::ERROR_USERNAME_INVALID;

        else if($record->user_password!==md5($this->password))

            $this->errorCode=self::ERROR_PASSWORD_INVALID;

        else

        {

            $this->_id=$record->id;

            $this->setState('title', $record->title);

            $this->errorCode=self::ERROR_NONE;

        }

        return !$this->errorCode;

    }

 

    public function getId()

    {

        return $this->_id;

    }