/** * testChangePassword * * @return void */ public function testChangePassword() { $postData = array(); $result = $this->User->changePassword($postData); $this->assertFalse($result); $postData = array('User' => array('id' => 1, 'old_password' => 'test', 'new_password' => 'not', 'confirm_password' => 'equal')); $result = $this->User->changePassword($postData); $this->assertFalse($result); $this->assertEqual(array('new_password', 'confirm_password'), array_keys($this->User->invalidFields())); $postData = array('User' => array('id' => 1, 'old_password' => 'test', 'new_password' => 'testtest', 'confirm_password' => 'testtest')); $result = $this->User->changePassword($postData); $this->assertTrue($result); $ressult = $this->User->find('first', array('recursive' => -1, 'conditions' => array('User.id' => 1))); $this->assertTrue(BcryptFormAuthenticate::check('testtest', $ressult['User']['password'])); }
/** * Validation method to check the old password * * @param array $password * @return boolean True on success */ public function validateOldPassword($password) { if (!isset($this->data[$this->alias][$this->primaryKey]) || empty($this->data[$this->alias][$this->primaryKey])) { if (Configure::read('debug') > 0) { throw new OutOfBoundsException(sprintf(__d('users', '%s has to be set and not empty'), $this->data[$this->alias][$this->primaryKey])); } } $current_password = $this->field('password', array($this->alias . '.id' => $this->data[$this->alias]['id'])); return BcryptFormAuthenticate::check($password['old_password'], $current_password); }