sasori Posted October 26, 2008 Share Posted October 26, 2008 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 More sharing options...
DarkWater Posted October 27, 2008 Share Posted October 27, 2008 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."); } } } Link to comment https://forums.phpfreaks.com/topic/130157-retype-password-confirmationcakephp/#findComment-675294 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.