1 |
jonen |
1.1 |
<?php |
2 |
|
|
/** |
3 |
|
|
* This file contains the Password FormElement class. |
4 |
|
|
* |
5 |
jonen |
1.2 |
* $Id: FEPassword.inc,v 1.9 2003/04/02 21:21:02 hemna Exp $ |
6 |
jonen |
1.1 |
* |
7 |
|
|
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
8 |
|
|
* @author Suren Markosyan <suren@bcsweb.com> |
9 |
|
|
* @package phpHtmlLib |
10 |
|
|
* @subpackage FormProcessing |
11 |
|
|
* |
12 |
|
|
* @copyright LGPL - See LICENCE |
13 |
|
|
* |
14 |
|
|
*/ |
15 |
|
|
|
16 |
|
|
/** |
17 |
|
|
* This is the Password FormElement which builds a |
18 |
|
|
* input field of type="password". It validates |
19 |
|
|
* the data as is_password(). |
20 |
|
|
* |
21 |
|
|
* NOTE: this is used in conjunction with the |
22 |
|
|
* FEConfirmPassword object to ensure the |
23 |
|
|
* user's input is what they wanted. |
24 |
|
|
* |
25 |
|
|
* |
26 |
|
|
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
27 |
|
|
* @author Suren Markossian <suren@bcsweb.com> |
28 |
|
|
* @package phpHtmlLib |
29 |
|
|
* @subpackage FormProcessing |
30 |
|
|
* |
31 |
|
|
* @copyright LGPL - See LICENCE |
32 |
|
|
*/ |
33 |
|
|
class FEPassword extends FEText { |
34 |
|
|
|
35 |
|
|
/** |
36 |
|
|
* This function builds and returns the |
37 |
|
|
* form element object |
38 |
|
|
* |
39 |
|
|
* @return object |
40 |
|
|
*/ |
41 |
|
|
function get_element() { |
42 |
|
|
$attributes = $this->_build_element_attributes(); |
43 |
|
|
$attributes["type"] = "password"; |
44 |
|
|
$attributes["value"] = ''; |
45 |
|
|
return new INPUTtag($attributes); |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
|
49 |
|
|
/** |
50 |
|
|
* This function performs the actual validation |
51 |
|
|
* It is called only if the validation is required by |
52 |
|
|
* this element |
53 |
|
|
* |
54 |
|
|
* This function is responsible for performing complete |
55 |
|
|
* validation and setting the appropriate error message |
56 |
|
|
* in case of a failed validation |
57 |
|
|
* |
58 |
jonen |
1.2 |
* @param FormValidation object |
59 |
jonen |
1.1 |
*/ |
60 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
61 |
|
|
if (!$_FormValidation->is_password($this->get_value())) { |
62 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
63 |
jonen |
1.1 |
return FALSE; |
64 |
|
|
} |
65 |
|
|
return TRUE; |
66 |
|
|
} |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
/** |
70 |
|
|
* This is the ConfirmPassword FormElement which builds a |
71 |
|
|
* input field of type="password". It requires the caller |
72 |
|
|
* to add a FEPassword object to this class to have something |
73 |
|
|
* to compare during validation time. |
74 |
|
|
* It first validates that the value is_password(), and then |
75 |
|
|
* makes sure it matches exactly what the value is in |
76 |
|
|
* the FEPassword. |
77 |
|
|
* |
78 |
|
|
* USE: after u create the FEConfirmPassword, you MUST call |
79 |
|
|
* password() method which adds a reference to the FEPassword |
80 |
|
|
* object, so it can validate against. |
81 |
|
|
* |
82 |
|
|
* |
83 |
|
|
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
84 |
|
|
* @author Suren Markossian <suren@bcsweb.com> |
85 |
|
|
* @package phpHtmlLib |
86 |
|
|
* @subpackage FormProcessing |
87 |
|
|
* |
88 |
|
|
* @copyright LGPL - See LICENCE |
89 |
|
|
*/ |
90 |
|
|
class FEConfirmPassword extends FEPassword { |
91 |
|
|
|
92 |
|
|
/** |
93 |
|
|
* This holds the FEPassword we are |
94 |
|
|
* trying to confirm |
95 |
|
|
*/ |
96 |
|
|
var $_fepassword = NULL; |
97 |
|
|
|
98 |
|
|
/** |
99 |
|
|
* use this function to add the |
100 |
|
|
* FEPassword object that we want |
101 |
|
|
* to confirm. |
102 |
|
|
* |
103 |
|
|
* @param FEPassword object |
104 |
|
|
*/ |
105 |
|
|
function password( &$fepassword ) { |
106 |
|
|
$this->_fepassword = &$fepassword; |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
|
110 |
|
|
/** |
111 |
|
|
* This function performs the actual validation |
112 |
|
|
* It is called only if the validation is required by |
113 |
|
|
* this element |
114 |
|
|
* |
115 |
|
|
* This function is responsible for performing complete |
116 |
|
|
* validation and setting the appropriate error message |
117 |
|
|
* in case of a failed validation |
118 |
|
|
* |
119 |
jonen |
1.2 |
* @param FormValidation object |
120 |
jonen |
1.1 |
*/ |
121 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
122 |
|
|
if (!$_FormValidation->is_password($this->get_value())) { |
123 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
124 |
jonen |
1.1 |
return FALSE; |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
if ($this->_fepassword == NULL) { |
128 |
|
|
$this->set_error_message( "No Password to confirm. ". |
129 |
|
|
"please use FEConfirmPassword::password() ". |
130 |
|
|
"to set the FEPassword you wish to ". |
131 |
|
|
"confirm"); |
132 |
|
|
return FALSE; |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
//looks like we have an FEPassword to confirm against |
136 |
jonen |
1.2 |
if (!$_FormValidation->is_confirm_password($this->get_value(), |
137 |
|
|
$this->_fepassword->get_value())) { |
138 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
139 |
jonen |
1.1 |
return FALSE; |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
return TRUE; |
143 |
|
|
} |
144 |
|
|
} |
145 |
|
|
?> |