1<?php
2
3namespace dokuwiki\plugin\config\core\Setting;
4
5/**
6 * Class setting_password
7 */
8class SettingPassword extends SettingString {
9
10    protected $code = 'plain';  // mechanism to be used to obscure passwords
11
12    /** @inheritdoc */
13    public function update($input) {
14        if($this->isProtected()) return false;
15        if(!$input) return false;
16
17        if($this->pattern && !preg_match($this->pattern, $input)) {
18            $this->error = true;
19            $this->input = $input;
20            return false;
21        }
22
23        $this->local = conf_encodeString($input, $this->code);
24        return true;
25    }
26
27    /** @inheritdoc */
28    public function html(\admin_plugin_config $plugin, $echo = false) {
29
30        $disable = $this->isProtected() ? 'disabled="disabled"' : '';
31
32        $key = htmlspecialchars($this->key);
33
34        $label = '<label for="config___' . $key . '">' . $this->prompt($plugin) . '</label>';
35        $input = '<input id="config___' . $key . '" name="config[' . $key .
36            ']" autocomplete="off" type="password" class="edit" value="" ' . $disable . ' />';
37        return array($label, $input);
38    }
39}
40