Yii Framework Forum: Password always incorrect after signing up - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Password always incorrect after signing up

#1 User is offline   noobkoder 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 02-November 17

Posted 10 March 2018 - 09:51 AM

In my advanced application, after signing up it supposed to be already logged in but after signing up and trying to login it always says that I input the right credentials even though I tried testing it using "qwerty" as a password.

I haven't done anything yet on the signup form model only the customization that is needed to match the user table.

When I check the database it records the data but everytime I login it always says that I input the wrong credentials.

public function rules()
    {
        return [
            ['username', 'trim'],
            ['username', 'required'],
            ['username', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This username has already been taken.'],
            ['username', 'string', 'min' => 2, 'max' => 255],

            ['email', 'trim'],
            ['email', 'required'],
            ['email', 'email'],
            ['email', 'string', 'max' => 255],
            ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'],

            ['password', 'required'],
            ['password', 'string', 'min' => 6],

            ['first_name', 'required'],
            ['first_name', 'string', 'max' => 45],

            ['middle_name', 'string', 'max' => 45],

            ['last_name', 'required'],
            ['last_name', 'string', 'max' => 45],

            ['contact', 'required'],
            ['contact', 'string', 'max' => 11],

            ['birth_date', 'required'],

            ['type', 'required'],
            ['type', 'string', 'max' => 45],

            ['external_type', 'string', 'max' => 45],

            ['status', 'string', 'max' => 45],

            ['region_id', 'required'],
            ['barangay_id', 'required'],
            ['province_id', 'required'],
            ['city_municipal_id', 'required'],



this is the signup()

 public function signup()
    {
        if (!$this->validate()) {
            return null;
        }
        
        $user = new User();
        $user->username = $this->username;
        $user->email = $this->email;
        $user->setPassword($this->password);
        $user->generateAuthKey();

        $user->first_name = $this->first_name;
        $user->middle_name = $this->middle_name;
        $user->last_name = $this->last_name;
        $user->contact = $this->contact;
        $user->birth_date = $this->birth_date;
        $user->type = $this->type;
        $user->external_type = $this->external_type;
        $user->status = $this->status;
        $user->region_id = $this->region_id;
        $user->barangay_id = $this->barangay_id;
        $user->province_id = $this->province_id;
        $user->city_municipal_id = $this->city_municipal_id;

        return $user->save() ? $user : null;
            
    }

0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,646
  • Joined: 16-February 11
  • Location:Japan

Posted 10 March 2018 - 11:56 PM

Hi,

I don't see anything wrong in your posted code.

Quote

after signing up and trying to login it always says that I input the right credentials even though I tried testing it using "qwerty" as a password.

Do you say that you tried to login when you were already logged in? But usually you can't access login action when you are logged in.

Quote

but everytime I login it always says that I input the wrong credentials.

This seems to contradict what you say in the first quote.
0

#3 User is offline   noobkoder 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 02-November 17

Posted 11 March 2018 - 04:41 AM

View Postsoftark, on 10 March 2018 - 11:56 PM, said:

Hi,

I don't see anything wrong in your posted code.


Do you say that you tried to login when you were already logged in? But usually you can't access login action when you are logged in.

This seems to contradict what you say in the first quote.


Sorry what I mean is that after the registration

After registration, it redirects me to the index page but it still not logged in it supposed to be already logged in after signing up right? But when I try to login again it always says wrong password even though I entered the right password.

EDIT 2:

After browsing the forum I've found a similar problem
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,646
  • Joined: 16-February 11
  • Location:Japan

Posted 11 March 2018 - 11:32 AM

View Postnoobkoder, on 11 March 2018 - 04:41 AM, said:

After browsing the forum I've found a similar problem


What about the configuration of 'user' component?
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],

If you have a different class name for the user table, you have to modify this part accordingly.
0

#5 User is offline   noobkoder 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 02-November 17

Posted 11 March 2018 - 11:50 AM

View Postsoftark, on 11 March 2018 - 11:32 AM, said:

What about the configuration of 'user' component?
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],

If you have a different class name for the user table, you have to modify this part accordingly.



I don't have a different classname, I tried installing Yii2 again, I used the user table (My link) after the migration. I tried registering another user, and nothing happens. It just load again the page.
0

#6 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,646
  • Joined: 16-February 11
  • Location:Japan

Posted 11 March 2018 - 12:21 PM

View Postnoobkoder, on 11 March 2018 - 11:50 AM, said:

I don't have a different classname, I tried installing Yii2 again, I used the user table (My link) after the migration. I tried registering another user, and nothing happens. It just load again the page.

The table in your link doesn't have 'first_name', 'middle_name', 'last_name', ... etc. What is the table name (and the corresponding model name) that has those fields?
0

#7 User is offline   noobkoder 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 02-November 17

Posted 12 March 2018 - 07:57 AM

View Postsoftark, on 11 March 2018 - 12:21 PM, said:

The table in your link doesn't have 'first_name', 'middle_name', 'last_name', ... etc. What is the table name (and the corresponding model name) that has those fields?


Yes the table in my link is just an example because I've tried to create a new one but it still doesn't work even I only used the user table that came from the yii migration.

Here is the user table that I've been using.

I'm still stuck here hahaha, maybe I will just try to install a lower version of Yii2 Advanced App
0

#8 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,646
  • Joined: 16-February 11
  • Location:Japan

Posted 12 March 2018 - 08:36 AM

View Postnoobkoder, on 12 March 2018 - 07:57 AM, said:

I'm still stuck here hahaha, maybe I will just try to install a lower version of Yii2 Advanced App

Hold on, my friend. You're gonna make it all right! :)

Yeah, I agree with you. I would start from the scratch again, installing yii2-app-advanced anew, and confirm that signing-up and logging-in work as expected before proceeding to the customization of the user model.
0

#9 User is offline   noobkoder 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 02-November 17

Posted 14 March 2018 - 10:10 AM

View Postsoftark, on 12 March 2018 - 08:36 AM, said:

Hold on, my friend. You're gonna make it all right! :)

Yeah, I agree with you. I would start from the scratch again, installing yii2-app-advanced anew, and confirm that signing-up and logging-in work as expected before proceeding to the customization of the user model.


So I started again from scratch and I used the the user table from migration, after signing up it works fine also the login. I proceed with the customization of the SignupForm model and it doesn't work anymore but it records the data the I filled up in the user table.

The User Table

The data was been saved in the user table
0

#10 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,646
  • Joined: 16-February 11
  • Location:Japan

Posted 14 March 2018 - 05:59 PM

View Postnoobkoder, on 14 March 2018 - 10:10 AM, said:

So I started again from scratch and I used the the user table from migration, after signing up it works fine also the login. I proceed with the customization of the SignupForm model and it doesn't work anymore but it records the data the I filled up in the user table.


OK.

Did you change the configuration of the 'user' component? If you are using "SignupForm" model in place of the "User" model, you have to re-configure it.
        'user' => [
            // 'identityClass' => 'common\models\User',
            'identityClass' => 'common\models\SignupForm',  // or something like that
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
        ],


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users