Home | About | Web Stories | View All Posts

12 Dec 2021

Yii2 login with database - Yii2 advanced login not working after installation

Yii2 framework with advanced template provides inbuilt login and signup page and funtionality by default. First you need to signup into Yii2 application.

Signup page sample url -

But you can not login, when you try to login after successful signup. Login page sample url -

The problem is due to USER STATUS value check in "function findByUsername()" while login that is written in the Yii2 User class file or model, which are -


User class file path and code - yii2project/common/models/Users.php
public static function findByUsername($username)
        return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]);
Yii2 framework assigns the user STATUS = 9 to the user after signup in the database table - "user" as screenshot below -

Yii2 gets new registered user status INACTIVE, that is why you get - "Incorrect username or password" error.

You need to edit or update the user status field to 10 in the user table and then try to login. The login activity will work successfully.
Tags :
Aashutosh Kumar Yadav

By Aashutosh Kumar Yadav

He is a PHP-based UI/Web designer and developer by profession and very interested in technical writing and blogging. He has been writing technical content for about 10 years and has proficient in practical knowledge and technical writing.


Post a Comment