Unable To Login

Sorry, this is a really newbie question. I’m following the blog tutorial from the official site, and I have my code like the following. After I made the changes, hitting login only goes to a blank page. Other pages are still accessible, but they still show that I’m not logged in. Any input is appreciated :)

Angela




/*UserIdentity.php*/

class UserIdentity extends CUserIdentity

{


  private $_id;


  public function getId() {

  	return $this->_id;

  }

	

	public function authenticate() {

  	$username = strtolower($this->username);

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


  	if($user === null) {

  		$this->errorCode = self::ERROR_USERNAME_INVALID;

  	} elseif(!$user->validatePassword($this->password)) {

  		$this->errorCode = self::ERROR_PASSWORD_INVALID;

  	} else {

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

  		$this->username = $user->username;

  		$this->errorCode = self::ERROR_NONE;

  	}


  	return $this->errorCode == self::ERROR_NONE;

  }

}




/*User.php -> Under Models*/

	public function hashPassword($password) {

		return crypt($password, $this->generateSalt());

	}


	public function validatePassword($password) {

		return crypt($password, $this->password) === $this->password;

	}




/*LoginForm.php - Unmodified*/

	/**

	 * Authenticates the password.

	 * This is the 'authenticate' validator as declared in rules().

	 */

	public function authenticate($attribute,$params)

	{

		if(!$this->hasErrors())

		{

			$this->_identity=new UserIdentity($this->username,$this->password);

			if(!$this->_identity->authenticate())

				$this->addError('password','Incorrect username or password.');

		}

	}


	/**

	 * Logs in the user using the given username and password in the model.

	 * @return boolean whether login is successful

	 */

	public function login()

	{

		if($this->_identity===null)

		{

			$this->_identity=new UserIdentity($this->username,$this->password);

			$this->_identity->authenticate();

		}

		if($this->_identity->errorCode===UserIdentity::ERROR_NONE)

		{

			$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days

			Yii::app()->user->login($this->_identity,$duration);

			return true;

		}

		else

			return false;

	}



don’t look at the code, it’s fine if you copy and paste from demo.

  1. in windows, check in php.ini, search for

;extension=php_pdo.dll

;extension=php_sqlite.dll

remove semi-colon and restart webserver;

  1. if in linux, check above + check file /protected/data/testdrive.db to make sure it’s writable

good luck.

Thanks for the reply, I actually found the sql file for MySQL and I imported it into mysql, a database called first. I have double checked on the database connection. It looks fine.