Jump to content

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 comment
https://forums.phpfreaks.com/topic/130157-retype-password-confirmationcakephp/
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
		$this->redirect('/users');
	}
	if (!empty($this->data)) {
		if ($this->data['User']['password'] == $this->Auth->password($this->data['User']['confirm'])) {
			if ($this->User->save($this->data)) {
				$this->redirect('/users/login');
			}
		}
		else {
			$this->Session->setFlash("Your passwords did not match.");
		}
	}
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.