title: yii2 login always return false
body: <p>I am trying to implement login function with database using Yii 2.0. I have tried for 3 days but it still not working. What did i do wrong?</p>
  
  <p>Here is my user and loginform class</p>
  
  <p><strong>loginform.php</strong></p>
  
  <pre><code>&lt;?php
  
  namespace app\models;
  
  use Yii;
  use yii\base\Model;
  
  /**
   * LoginForm is the model behind the login form.
   */
  class LoginForm extends Model
  {
      public $username;
      public $password;
      public $rememberMe = true;
  
      private $_user = false;
  
      /**
       * @return array the validation rules.
       */
      public function rules()
      {
          return [
              // username and password are both required
              [['username', 'password'], 'required'],
              // rememberMe must be a boolean value
              ['rememberMe', 'boolean'],
              // password is validated by validatePassword()
              ['password', 'validatePassword'],
          ];
      }
  
      /**
       * Validates the password.
       * This method serves as the inline validation for password.
       *
       * @param string $attribute the attribute currently being validated
       * @param array $params the additional name-value pairs given in the rule
       */
      public function validatePassword($attribute, $params)
      {
          if (!$this-&gt;hasErrors()) {
              $user = $this-&gt;getUser();
  
              if (!$user || !$user-&gt;validatePassword($this-&gt;password)) {
                  $this-&gt;addError($attribute, 'Incorrect username or password.');
              }
          }
      }
  
      /**
       * Logs in a user using the provided username and password.
       * @return boolean whether the user is logged in successfully
       */
      public function login()
      {
          if ($this-&gt;validate()) {
              return Yii::$app-&gt;user-&gt;login($this-&gt;getUser(), $this-&gt;rememberMe ? 3600*24*30 : 0);
          } else {
              return false;
          }
      }
  
      /**
       * Finds user by [[username]]
       *
       * @return User|null
       */
      public function getUser()
      {
          if ($this-&gt;_user === false) {
              $this-&gt;_user = User::findByUsername($this-&gt;username);
  
          }
  
          return $this-&gt;_user;
      }
  }
  </code></pre>
  
  <p><strong>User.php</strong></p>
  
  <pre><code>&lt;?php
  
  namespace app\models;
  use Yii;
  
  use yii\base\NotSupportedException;
  use yii\helpers\Security;
  use yii\web\IdentityInterface;
  
  class User extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface
  {
  
      public static function tableName()
      {
          return 'usys.usex';
      }
      public function rules()
      {
          return [
              [['passwd', 'user_name'], 'required'],
              [['user_type_uid', 'user_status_uid', 'msisdn', 'passwd_strength', 'banned', 'created'], 'integer']
          ];
      }
      public function attributeLabels()
      {
          return [
              'usex_uid' =&gt; 'User id',
              'username' =&gt; 'Username',
              'password' =&gt; 'Password'
          ];
      }
      /**
       * @inheritdoc
       */
      public static function findIdentity($id)
      {
          return isset(self::$users[$id]) ? new static(self::$users[$id]) : null;
      }
  
      /**
       * @inheritdoc
       */
      public static function findIdentityByAccessToken($token, $type = null)
      {
          foreach (self::$users as $user) {
              if ($user['accessToken'] === $token) {
                  return new static($user);
  
              }
          }
  
          return null;
      }
  
      /**
       * Finds user by username
       *
       * @param  string      $username
       * @return static|null
       */
      public static function findByUsername($username) {
          $user = self::find()
                  -&gt;where(["user_uid" =&gt; $username])
                  -&gt;one();
          if (!count($user)) {
              return null;
          }
          return new static($user);
      }
  
      /**
       * @inheritdoc
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      /**
       * @inheritdoc
       */
      public function getAuthKey()
      {
          return $this-&gt;authKey;
      }
  
      /**
       * @inheritdoc
       */
      public function validateAuthKey($authKey)
      {
          return $this-&gt;authKey === $authKey;
      }
  
      /**
       * Validates password
       *
       * @param  string  $password password to validate
       * @return boolean if password provided is valid for current user
       */
      public function validatePassword($password)
      {
  
          return $this-&gt;password === $password;
      }
  }
  </code></pre>
  
  <p>I try to trace validation function to validateAnswer but when i tried to print <code>$this-&gt;password</code> it doesn't have any value.
  Anyone has a clue?</p>