views:

83

answers:

1

Here's my scenario: I'm creating a password change page. the real field that holds the password is User.password

On the password create page, I used 3 made up fields: $form->input('User.old_passwd'); $form->input('User.new_passwd'); $form->input('User.confirm_new_passwd');

How do I validate them with the rules:

  • old password must match User.password
  • new_passwd and confirmnew_passwd must be equal

Are there better solutions for this? I'm open for suggestions. Thanks!

+1  A: 

The built-in authentication component doesn't offer that functionality. I would specify the validation rules for your "made up" fields in the validate property of the model and write my own validation methods, for example: correctPassword() to ensure that the users enter their old password and matchingPasswords() to ensure that the new password was re-typed correctly.

var $validate = array(
    // your existing validation rules
    'old_passwd' => array(
            'rule' => 'correctPassword',
            'message' => 'invalid password'
    ),
    'new_passwd' => array(
            'rule' => array('minLength', 8),
            'message' => '8 characters minimum';
    ),
    'confirm_new_passwd' => array(
            'rule' => 'matchingPasswords',
            'message' => 'passwords do not match'
    )
);

function correctPassword($check) { }
function matchingPasswords($check) { }

See the Cookbook for more information about custom validation rules.

Mike