how to authorize using email and passowrd in useridenty class

hi i want to login user with email and password what will i have to change to do that?

You have to save in some database table the authorized email and password.

Then you can change the useridentiy class like that:




	public function authenticate()

	{

		$user=User::model()->find('username=:username', array(':username'=>$this->username));

		if(!$user)

			$this->errorCode=self::ERROR_USERNAME_INVALID;

		else if($user->password!==$this->password)

			$this->errorCode=self::ERROR_PASSWORD_INVALID;

		else

			$this->errorCode=self::ERROR_NONE;

		return !$this->errorCode;

	}



i don’t have the username in my user table i want user to insert email instead of username and password, then the authenticate should check the email and the password.

You have to save in some database table the authorized email and password.

Then you can change the useridentiy class like that:




	public function authenticate()

	{

		$user=User::model()->find('email=:email', array(':email'=>$this->email));

		if(!$user)

			$this->errorCode=self::ERROR_USERNAME_INVALID;

		else if($user->password!==$this->password)

			$this->errorCode=self::ERROR_PASSWORD_INVALID;

		else

			$this->errorCode=self::ERROR_NONE;

		return !$this->errorCode;

	}



this is giving error i m using


findByAttributes(array('email'=>$this->username));

this is working fine.

I must be learning a thing or two about this framework because I had the same problem and can answer this.

I used code similar to that in the guide:


class UserIdentity extends CUserIdentity

{

    private $_id;

    public function authenticate()

    {

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

        if($record===null)

            $this->errorCode=self::ERROR_USERNAME_INVALID;

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

            $this->errorCode=self::ERROR_PASSWORD_INVALID;



The username parameter seems to be hardcoded.

Using Zaccaria’s example with the find() method makes more intuitive sense.

I think that my example has a mistake, as UserIdentity has only the property username.

What I do, is to use a field named username in database and then I put an email here, that is more intuitive for me.

hi when i enter wrong credentials in the form it still displays: Incorrect username or password.

can i change it to: Incorrect Email or password.

???