Yii Framework Forum

Password compare not working on different scenarios


(varunsaini) #1

Hi,

I’m new to this forum ans Yii2.
I’m facing issues while password compare validation. while creating user this is working fine, but on update this is not working.

I’m using two scenarios for validation.
Profile update scenario:

[['password','password_repeat'], 'safe', 'on' => 'profile_update'],
            ['password_repeat', 'compare', 'compareAttribute'=>'password', 'message'=>"Passwords are not matching!" , 'on' => 'profile_update'],

Profile creation scenario:

 [['code', 'first_name', 'last_name', 'email', 'phone', 'roles_id', 'username', 'password', 'password_repeat', 'access_type'], 'required', 'on' => 'new_user'],

public function scenarios() {
        $scenarios = parent::scenarios();
        $scenarios['profile_update'] = ['first_name', 'last_name', 'email', 'phone', 'manager_id', 'code', 'password', 'password_repeat'];
        $scenarios['new_user'] = ['code', 'first_name', 'last_name', 'email', 'phone', 'roles_id', 'username', 'password', 'password_repeat', 'access_type'];
        $scenarios['first_login'] = ['code', 'first_name', 'last_name', 'email', 'phone', 'roles_id', 'username', 'newPassword', 'newPasswordRepeat', 'access_type'];
        return $scenarios;
    }

Request you to please me where I’m doing mistake.

Thanks


(Alexander Makarov) #2

How exactly it doesn’t work?