2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2007-09-15 23:38:05 +02:00
|
|
|
* Password input field.
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-formattedinput
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2011-12-21 17:35:42 +01:00
|
|
|
class PasswordField extends TextField {
|
2007-09-15 23:38:05 +02:00
|
|
|
|
2013-06-11 23:09:51 +02:00
|
|
|
/**
|
|
|
|
* Controls the autocomplete attribute on the field.
|
|
|
|
*
|
|
|
|
* Setting it to false will set the attribute to "off", which will hint the browser
|
|
|
|
* to not cache the password and to not use any password managers.
|
|
|
|
*/
|
|
|
|
private static $autocomplete;
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-15 23:38:05 +02:00
|
|
|
* Returns an input field, class="text" and type="text" with an optional
|
|
|
|
* maxlength
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function __construct($name, $title = null, $value = "") {
|
2012-09-26 23:34:00 +02:00
|
|
|
if(count(func_get_args()) > 3) {
|
|
|
|
Deprecation::notice('3.0', 'Use setMaxLength() instead of constructor arguments',
|
|
|
|
Deprecation::SCOPE_GLOBAL);
|
|
|
|
}
|
2012-01-02 17:45:47 +01:00
|
|
|
|
2007-09-15 23:38:05 +02:00
|
|
|
parent::__construct($name, $title, $value);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-15 23:38:05 +02:00
|
|
|
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getAttributes() {
|
2013-06-11 23:09:51 +02:00
|
|
|
$attributes = array_merge(
|
2011-12-22 13:10:57 +01:00
|
|
|
parent::getAttributes(),
|
|
|
|
array('type' => 'password')
|
|
|
|
);
|
2013-06-11 23:09:51 +02:00
|
|
|
|
|
|
|
$autocomplete = Config::inst()->get('PasswordField', 'autocomplete');
|
|
|
|
if (isset($autocomplete)) {
|
|
|
|
$attributes['autocomplete'] = $autocomplete ? 'on' : 'off';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $attributes;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-15 23:38:05 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-15 23:38:05 +02:00
|
|
|
* Makes a pretty readonly field with some stars in it
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function performReadonlyTransformation() {
|
2012-12-13 13:51:28 +01:00
|
|
|
$field = $this->castedCopy('ReadonlyField');
|
|
|
|
$field->setValue('*****');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $field;
|
|
|
|
}
|
2011-12-22 13:10:57 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Type() {
|
2011-12-22 13:10:57 +01:00
|
|
|
return 'text password';
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-15 23:38:05 +02:00
|
|
|
|