私は、ユーザがパスワードを変更できるページを構築しています。彼らは2つのフィールドを埋める必要があり、両方が一致する必要があります変更する前に、彼らは彼らのプロフィールページに成功するとリダイレクトされます。CakePHP 2.1のユーザのパスワードを変更してください。
は、これまでのところ私は、以下の方法で構築しています:
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?'));
}
}
}
を、これは形式です:だからあなたは計画がパスワード2でそれが言う取り、保存することです見ることができるよう
<?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(); ?>
セキュリティハッシュを使用してデータベースパスワードフィールドに入力します。しかし何が起こるかは、代わりに新しいユーザーを作成することですが、空のデータが...ここで間違っていますか?そして、どのように私は2つのパスワードフィールドを比較しますか?
あなたは行動がそのの世話をさせることができます:http://www.dereuromark.de/2011/08/25/working-with- passwords-in-cakephp/- または、少なくともあなた自身のアプローチに適した解決策を見つけるために提供される機能の一部を取ること。 – mark
なぜ私のコードは新しいユーザーを作成しますか? – Cameron
パスワードフィールドと比較します。 http://stackoverflow.com/questions/17185246/password-confirm-validation-cakephp/18017468#18017468 – Ketan