I could not log in using database

Hi I am having trouble in loginform I am using database.In my user table i have 3 columns id,username and password.

every time i log in it always says "Invalid username or password"

model/LoginForm.php




<?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->hasErrors()) {

            $user = $this->getUser();





            if (!$user || !$user->validatePassword($this->password)) {

                $this->addError($attribute, 'Incorrect username or password.'.$this->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->validate()) {

            return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30 : 0);

        } else {

            return false;

        }

    }


    /**

     * Finds user by [[username]]

     *

     * @return User|null

     */

    public function getUser()

    {

        if ($this->_user === false) {

            $this->_user = User::findByUsername($this->username);

        }


        return $this->_user;

    }

}






model/User.php




<?php


namespace app\models;


class User extends \yii\db\ActiveRecord

{

    public $id;

    public $username;

    public $password;

   // public $authKey;

   // public $accessToken;


   /* private static $users = [

        '100' => [

            'id' => '100',

            'username' => 'admin',

            'password' => 'admin',

            'authKey' => 'test100key',

            'accessToken' => '100-token',

        ],

        '101' => [

            'id' => '101',

            'username' => 'demo',

            'password' => 'demo',

            'authKey' => 'test101key',

            'accessToken' => '101-token',

        ],

    ];*/




    /**

     *  Getting the table name

     *

     */


    public static function tableName()

    {

        return 'user';

    }


    /**

     * @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)

    {

        /*foreach (self::$users as $user) {

            if (strcasecmp($user['username'], $username) === 0) {

                return new static($user);

            }

        }*/


        $user = User::find()->where(['username' => $username])->one();


        return $user;

    }


    /**

     * @inheritdoc

     */

    public function getId()

    {

        return $this->id;

    }


    /**

     * @inheritdoc

     */

    public function getAuthKey()

    {

        return $this->authKey;

    }


    /**

     * @inheritdoc

     */

    public function validateAuthKey($authKey)

    {

        return $this->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->password === $password;

    }

}






view/login.php




<?php

use yii\helpers\Html;

use yii\bootstrap\ActiveForm;


/* @var $this yii\web\View */

/* @var $form yii\bootstrap\ActiveForm */

/* @var $model app\models\LoginForm */


$this->title = 'Login';

$this->params['breadcrumbs'][] = $this->title;

?>

<div class="site-login">

    <h1><?= Html::encode($this->title) ?></h1>


    <p>Please fill out the following fields to login:</p>


    <?php $form = ActiveForm::begin([

        'id' => 'login-form',

        'options' => ['class' => 'form-horizontal'],

        'fieldConfig' => [

            'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>",

            'labelOptions' => ['class' => 'col-lg-1 control-label'],

        ],

    ]); ?>


    <?= $form->field($model, 'username') ?>


    <?= $form->field($model, 'password')->passwordInput() ?>


    <?= $form->field($model, 'rememberMe', [

        'template' => "<div class=\"col-lg-offset-1 col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>",

    ])->checkbox() ?>


    <div class="form-group">

        <div class="col-lg-offset-1 col-lg-11">

            <?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>

        </div>

    </div>


    <?php ActiveForm::end(); ?>


    <div class="col-lg-offset-1" style="color:#999;">

        You may login with <strong>admin/admin</strong> or <strong>demo/demo</strong>.<br>

        To modify the username/password, please check out the code <code>app\models\User::$users</code>.

    </div>

</div>






is password in your db hashed/encrypted?

NO,it is just plaint text password.