Password.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Form
  17. * @subpackage Element
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /** Zend_Form_Element_Xhtml */
  22. require_once 'Zend/Form/Element/Xhtml.php';
  23. /**
  24. * Password form element
  25. *
  26. * @category Zend
  27. * @package Zend_Form
  28. * @subpackage Element
  29. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. * @version $Id$
  32. */
  33. class Zend_Form_Element_Password extends Zend_Form_Element_Xhtml
  34. {
  35. /**
  36. * Use formPassword view helper by default
  37. * @var string
  38. */
  39. public $helper = 'formPassword';
  40. /**
  41. * Whether or not to render the password
  42. * @var bool
  43. */
  44. public $renderPassword = false;
  45. /**
  46. * Set flag indicating whether or not to render the password
  47. * @param bool $flag
  48. * @return Zend_Form_Element_Password
  49. */
  50. public function setRenderPassword($flag)
  51. {
  52. $this->renderPassword = (bool) $flag;
  53. return $this;
  54. }
  55. /**
  56. * Get value of renderPassword flag
  57. *
  58. * @return bool
  59. */
  60. public function renderPassword()
  61. {
  62. return $this->renderPassword;
  63. }
  64. /**
  65. * Override isValid()
  66. *
  67. * Ensure that validation error messages mask password value.
  68. *
  69. * @param string $value
  70. * @param mixed $context
  71. * @return bool
  72. */
  73. public function isValid($value, $context = null)
  74. {
  75. foreach ($this->getValidators() as $validator) {
  76. if ($validator instanceof Zend_Validate_Abstract) {
  77. $validator->setObscureValue(true);
  78. }
  79. }
  80. return parent::isValid($value, $context);
  81. }
  82. }