CakePHP 2 - Validating password fields

帅比萌擦擦* 提交于 2019-12-04 16:32:50

Make the validation rules like this

'pwd' => array(
    'length' => array(
        'rule'      => array('between', 8, 40),
        'message'   => 'Your password must be between 8 and 40 characters.',
    ),
),
'pwd_repeat' => array(
    'length' => array(
        'rule'      => array('between', 8, 40),
        'message'   => 'Your password must be between 8 and 40 characters.',
    ),
    'compare'    => array(
        'rule'      => array('validate_passwords'),
        'message' => 'The passwords you entered do not match.',
    )
)

And your validate_passwords function should be like this.

public function validate_passwords() {
    return $this->data[$this->alias]['pwd'] === $this->data[$this->alias]['pwd_repeat']
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!