Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'form/empty-passwords' of https://github.com/bakura10/zf2
Browse files Browse the repository at this point in the history
…into hotfix/2613
  • Loading branch information
weierophinney committed Oct 1, 2012
2 parents 0e48db0 + f5f5cee commit 0fdcf27
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
15 changes: 14 additions & 1 deletion library/Zend/Form/Element/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

namespace Zend\Form\Element;

use Zend\Form\Form;
use Zend\Form\Element;
use Zend\Form\ElementPrepareAwareInterface;

/**
* @category Zend
Expand All @@ -30,7 +32,7 @@
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Password extends Element
class Password extends Element implements ElementPrepareAwareInterface
{
/**
* Seed attributes
Expand All @@ -40,4 +42,15 @@ class Password extends Element
protected $attributes = array(
'type' => 'password',
);

/**
* Remove the password before rendering if the form fails in order to avoid any security issue
*
* @param Form $form
* @return mixed
*/
public function prepareElement(Form $form)
{
$this->setValue('');
}
}
26 changes: 26 additions & 0 deletions tests/ZendTest/Form/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@

class FormTest extends TestCase
{
/**
* @var Form
*/
protected $form;

public function setUp()
{
$this->form = new Form();
Expand Down Expand Up @@ -1099,5 +1104,26 @@ public function testSetDataIsTraversable()
$this->assertTrue($this->form->isValid());
}

public function testResetPasswordValueIfFormIsNotValid()
{
$this->form->add(array(
'type' => 'Zend\Form\Element\Password' ,
'name' => 'password'
));

$this->form->add(array(
'type' => 'Zend\Form\Element\Email',
'name' => 'email'
));

$this->form->setData(array(
'password' => 'azerty',
'email' => 'wrongEmail'
));

$this->assertFalse($this->form->isValid());
$this->form->prepare();

$this->assertEquals('', $this->form->get('password')->getValue());
}
}

0 comments on commit 0fdcf27

Please sign in to comment.