开发者

Validate passwords with CakePHP 1.3

How do I run validation checks on a password field in CakePHP, seeing that the password is hashed before I get a chance to run开发者_如何学Python any checks on it?


If you only have a single password field in your form, you will need to create a custom hash function that either does nothing, or, better, preserves the original password somewhere.

Most likely though you have two password fields in your form where the user is required to confirm the password. In this case, you perform your password validation rules on the second password field. This can automatically happen in a custom validation rule, remember that you have access to all other fields inside a validation function via $this->data. You can then confirm that the two passwords are identical as described here.


It works this way for me (in the model):

  public $validate = array(
        'password' => array(
            'minLength' => array(
                'rule' => array('minLength', '8')
            )
         )
    );

If you want to do more validations then create a custom validation method in the appropriate model. In the custom validation method hash password this way: Security::hash($this->data['User']['password'], null, true)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜