1 <?php
2 /**
3 * PasswordInput.php
4 *
5 * @author Elvyrra SAS
6 * @license http://rem.mit-license.org/ MIT
7 */
8
9 namespace Hawk;
10
11 /**
12 * This class describes the behavior of password inputs
13 *
14 * @package Form\Input
15 */
16 class PasswordInput extends FormInput{
17 const TYPE = "password";
18
19 /**
20 * Variable that has to be got from the database for displaying
21 *
22 * @var bool
23 */
24 public $get = false,
25
26 /**
27 * The decryption function
28 *
29 * @var callable
30 */
31 $decrypt = null,
32
33 /**
34 * The encryption function
35 *
36 * @var callable
37 */
38 $encrypt = null,
39
40 /**
41 * The input pattern
42 *
43 * @var string
44 */
45 $pattern = '/^(?=.*\d)(?=.*[a-zA-Z]).{6,16}$/';
46
47 /**
48 * Display the input
49 *
50 * @return string The HTML result to display
51 */
52 public function display(){
53 $decrypt = $this->decrypt;
54 $this->value = ($this->get && $decrypt && is_callable($decrypt)) ? $decrypt($this->value) : "";
55 return parent::display();
56 }
57
58 /**
59 * Check the submitted value
60 *
61 * @param Form $form The form this input is associated to
62 *
63 * @return bool True if the input format is correct, else False
64 */
65 public function check(&$form = null){
66 if(parent::check($form)) {
67 // Check the confirmation password
68 if(!empty($this->compare) && $form) {
69 if($this->value != $form->getData($this->compare)) {
70 $form->error($this->errorAt, Lang::get('form.password-comparison'));
71 return false;
72 }
73 }
74
75 return true;
76 }
77 else{
78 return false;
79 }
80 }
81
82
83 /**
84 * Get the input value, formatted for SQL database
85 *
86 * @return string The formatted value
87 */
88 public function dbvalue(){
89 if($this->encrypt && is_callable($this->encrypt)) {
90 return call_user_func($this->encrypt, $this->value);
91 }
92 else
93 return $this->value;
94 }
95 }
96