Jump to content

retype password confirmation?[cakephp]


Recommended Posts

let's say we need to validate a password by retyping it in a second form, how am i gonna

do that in a model? :(

i ended up copying a function script from someone's work as

	function validConfirm ($data, $compare) {
                foreach ($data as $field => $value) {
                $compare = $this->data[$this->alias][$compare[0]];
                return (Security::hash($value, null, true) === $compare);

and my validation ended up as

	var $validate = array(
		'password' => array(
			'modelValidateAccountPasswordStrength'	=> array('rule' => array('strengthCheck', 'password')),
      			'modelValidateAccountPasswordLength'	=> array('rule' => array('minLength', '7')),
      			'modelValidateNotEmpty'					=> array('rule' => VALID_NOT_EMPTY)
		'password2' => array(
			'rule' => array('validConfirm','password'),
			'message' => 'password not equal')

but there's an error, the 2nd password field says not match even if the passwords matched :(

and also there's an error with that function that i copied, the $compare[0] :( it says

"notice undefined p" because of the letter "p" in the label :(  ..

i read the manual and api and I saw this "equalTo" property, but I don't know how to use it, it doesn't do what i wanted to happen in the process

Link to post
Share on other sites

Err, I played around in Cake before and I just checked out my Users controller, and saw that I had this add() method:


public function add() {
	if ($this->Auth->user('id') > 0) { //logged in
	if (!empty($this->data)) {
		if ($this->data['User']['password'] == $this->Auth->password($this->data['User']['confirm'])) {
			if ($this->User->save($this->data)) {
		else {
			$this->Session->setFlash("Your passwords did not match.");

Link to post
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.