I'm building a page where a user can change their password. They must fill two fields and both must match before it will be changed and then they will be redirected to their profile page on success.
So far I have built the following method:
public function changePassword()
{
$user = $this->User->find('first', array(
'conditions' => array(
'User.id' => $this->Auth->user('id'))
));
if ($this->request->is('post') || $this->request->is('put'))
{
if ($this->User->save($this->request->data))
{
$this->User->saveField('password', AuthComponent::password($this->request->data['User']['password2']));
$this->Session->setFlash(__('Your password has been changed!'));
$this->redirect(array('controller'=>'profiles','action'=>'view','userName'=>$user['User']['username']));
}
else
{
$this->Session->setFlash(__('Whoops! Something went wrong... try again?'));
}
}
}
and this is the form:
<?php echo $this->Form->create(); ?>
<?php echo $this->Form->input('id',array('type'=>'hidden')); ?>
<?php echo $this->Form->input('password1',array('type'=>'text','label'=>array('text'=>'Enter your new password'))); ?>
<?php echo $this->Form->input('password2',array('type'=>'text','label'=>array('text'=>'Confirm your new password'))); ?>
<button type="submit">Save</button>
<?php echo $this->Form->end(); ?>
So as you can see the plan is to take what it says in password2 and save it in the database password field using the security hashing. But what happens is it creates a new user instead but with blank data... What am I doing wrong here? And how do I compare the two password fields...