current-password-validator Validates field "Input current password" in your model

  1. Requirements
  2. Usage

Validates field "Input current password" in your model.

Requirements

Yii 1.1 or above

Usage

class User extends CActiveRecord
{
    public $old_password;
    public $new_password;

    // ...  
    public function rules()
    {
        return array(      
            // ...        
            // Settings scenario
            array('old_password', 'required', 'on' => 'settings'),
            array('old_password', 'DCurrentPassword', 'on' => 'settings'), 
        ));
    }

    public function validatePassword($password)
    {
        return $this->hashPassword($password) === $this->password;
    }
}

Or:

public function rules()
{
    return array(

        // ...

        array('old_password, new_email, new_password, new_confirm', 'length', 'max'=>255),
        array('new_email', 'email'),         
        array('new_password', 'length', 'min'=>6, 'allowEmpty'=>true),
        array('new_confirm', 'compare', 'compareAttribute'=>'new_password'),

        array('old_password', 'DCurrentPassword', 
            'on'=>'settings', 
            'dependsOnAttributes'=>array('new_password', 'new_email'), 
            'emptyMessage'=>'Current password required for change email or password',
            'notValidMessage'=>'Current password is not correct',
        ),
    ));
}

More examples see there:

2 0
4 followers
447 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Validation
Developed by: ElisDN
Created on: Jan 2, 2013
Last updated: 11 years ago

Downloads

show all

Related Extensions