PluginProbe
Easy Basic Authentication – Add basic auth to site or admin area / 2.5
Easy Basic Authentication – Add basic auth to site or admin area v2.5
trunk 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4 1.4.1 1.5 1.5.1 1.5.2 1.5.3 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.7 1.7.1 1.8 1.8.1 1.9 All 50 releases
← All changes | class/easy-basic-authentication-form-class.php +35 -84 trunk2.5 View file →
@@ -45,20 +45,9 @@
45 45 '7' => array(
46 46 'id' => 'basic-auth-plugin-white-list',
47 47 'title' => __('Ip White list', 'easy-basic-authentication'),
48 48 'callback' => 'basic_auth_plugin_whitelist_cb',
49 - ),
50 - '8' => array(
51 - 'id' => 'basic-auth-plugin-url-white-list',
52 - 'title' => __('Url White list', 'easy-basic-authentication'),
53 - 'callback' => 'basic_auth_plugin_urlwhitelist_cb',
54 - ),
55 - '9' => array(
56 - 'id' => 'basic-auth-plugin-remove-data-after-uninstall',
57 - 'title' => __('Remove plugin data after uninstall', 'easy-basic-authentication'),
58 - 'callback' => 'basic_auth_plugin_remove_data_after_uninstall_cb',
59 - ),
60 -
49 + )
61 50 );
62 51 }
63 52
64 53 public function basic_auth_plugin_settings_init() {
@@ -110,13 +99,12 @@
110 99 $this->printInputText("text","basic_auth_plugin_username",esc_attr( $username ),'','off');
111 100 }
112 101
113 102 public function basic_auth_plugin_password_cb() {
114 - $password = get_option( 'basic_auth_plugin_password' );
115 - ?>
116 - <input type="password" name="basic_auth_plugin_password" value="" placeholder="<?php esc_attr_e('Enter the password', 'easy-basic-authentication'); ?>" autocomplete="off">
117 - <p class="description"><?php esc_html_e('Leave blank to keep the current password.', 'easy-basic-authentication'); ?></p>
118 - <?php
103 + $password = get_option( 'basic_auth_plugin_password' )
104 + ? __('Password entered', 'easy-basic-authentication')
105 + : __('Enter the password', 'easy-basic-authentication');
106 + $this->printInputText("password","basic_auth_plugin_password",'',$password,'','off');
119 107 }
120 108
121 109 public function basic_auth_plugin_admin_log_enable_cb() {
122 110 $enable = get_option( 'basic_auth_plugin_admin_log_enable' );
@@ -138,23 +126,11 @@
138 126 }
139 127
140 128 public function basic_auth_plugin_whitelist_cb() {
141 129 $white_list = get_option( 'basic_auth_plugin_whitelist' );
142 - $this->printInputText("text","basic_auth_plugin_whitelist",esc_attr( $white_list ),__('White list, separated by comma. Ex. 127.0.0.1, 1.1.1.1/20, 1.1.0.0 - 1.1.0.255', 'easy-basic-authentication'));
130 + $this->printInputText("text","basic_auth_plugin_whitelist",esc_attr( $white_list ),__('White list, separated by comma', 'easy-basic-authentication'));
143 131 }
144 -
145 - public function basic_auth_plugin_urlwhitelist_cb() {
146 - $white_list = get_option( 'basic_auth_plugin_urlwhitelist' );
147 - $this->printInputText("text","basic_auth_plugin_urlwhitelist",esc_attr( $white_list ),__('Url white list, separated by comma. Ex. /json/wp-, www.google.it,', 'easy-basic-authentication'));
148 - }
149 132
150 - public function basic_auth_plugin_remove_data_after_uninstall_cb() {
151 - $enable = get_option( 'basic_auth_plugin_remove_data_after_uninstall' );
152 - ?>
153 - <input type="checkbox" name="basic_auth_plugin_remove_data_after_uninstall" value="1" <?php checked( $enable, 1 ); ?>>
154 - <?php
155 - }
156 -
157 133 public function printInputText($type, $name, $value='', $placeholder = '', $autocomplete = 'off') {
158 134 echo "<input type='" . esc_attr($type) . "' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' placeholder='" . esc_attr($placeholder) . "' autocomplete='" . esc_attr($autocomplete) . "' >";
159 135 }
160 136
@@ -160,21 +136,16 @@
160 136
161 137
162 138 public function basic_auth_plugin_save_settings($param) {
163 139 if ( isset( $param['eba_submit'] ) ) {
164 - if ( ! isset( $param['_wpnonce'] ) || ! wp_verify_nonce( $param['_wpnonce'], 'basic-auth-plugin-settings-options' ) ) {
165 - return;
166 - }
167 140 $admin_enable = isset( $param['basic_auth_plugin_admin_enable'] ) ? 1 : 0;
168 141 $enable = isset( $param['basic_auth_plugin_enable'] ) ? 1 : 0;
169 142 $username = sanitize_text_field( $param['basic_auth_plugin_username'] );
170 - $password = isset( $param['basic_auth_plugin_password'] ) ? wp_unslash( $param['basic_auth_plugin_password'] ) : '';
143 + $password = sanitize_text_field( $param['basic_auth_plugin_password'] );
171 144 $log_enable = isset( $param['basic_auth_plugin_admin_log_enable'] ) ? 1 : 0;
172 145 $alert_enable = isset( $param['basic_auth_plugin_alert_enable'] ) ? 1 : 0;
173 146 $alert_email = sanitize_text_field( $param['basic_auth_plugin_alertemail'] );
174 147 $white_list = sanitize_text_field( $param['basic_auth_plugin_whitelist'] );
175 - $remove_data = isset( $param['basic_auth_plugin_remove_data_after_uninstall'] ) ? 1 : 0;
176 - $url_white_list = sanitize_text_field( $param['basic_auth_plugin_urlwhitelist'] );
177 148
178 149 if ( empty( $username ) ) {
179 150 add_settings_error(
180 151 'basic_auth_plugin_username',
@@ -184,11 +155,16 @@
184 155 );
185 156 return;
186 157 }
187 158
188 - if ( ! empty( $password ) ) {
189 - $hashed_password = wp_hash_password( $password );
190 - update_option( 'basic_auth_plugin_password', $hashed_password );
159 + if ( empty( $password ) ) {
160 + add_settings_error(
161 + 'basic_auth_plugin_password',
162 + 'basic_auth_plugin_password_error',
163 + __('Password cannot be empty', 'easy-basic-authentication'),
164 + 'error'
165 + );
166 + return;
191 167 }
192 168
193 169 if ( is_email( $alert_email ) || (!$alert_enable && $alert_email=='' ) ) {
194 170 update_option( 'basic_auth_plugin_alertemail', $alert_email );
@@ -206,10 +182,8 @@
206 182 update_option( 'basic_auth_plugin_enable', $enable );
207 183 update_option( 'basic_auth_plugin_username', $username );
208 184 update_option( 'basic_auth_plugin_admin_log_enable', $log_enable );
209 185 update_option( 'basic_auth_plugin_alert_enable', $alert_enable );
210 - update_option( 'basic_auth_plugin_remove_data_after_uninstall', $remove_data );
211 - update_option( 'basic_auth_plugin_urlwhitelist', $url_white_list );
212 186
213 187 if( $this->validateIpList( $white_list ) || strlen($white_list) == 0 ) {
214 188 update_option( 'basic_auth_plugin_whitelist', $white_list );
215 189 } else {
@@ -222,9 +196,13 @@
222 196 return;
223 197
224 198 }
225 199
226 - $this->send_credentials_email($username, $password);
200 + if ( ! empty( $password ) ) {
201 + $hashed_password = wp_hash_password( $password );
202 + update_option( 'basic_auth_plugin_password', $hashed_password );
203 + $this->send_credentials_email($username, $password);
204 + }
227 205 }
228 206 }
229 207
230 208 public function basic_auth_plugin_settings_page() {
@@ -234,37 +212,15 @@
234 212 public function validateIpList($white_list) {
235 213 $ips = explode(',', $white_list);
236 214 foreach ($ips as $ip) {
237 215 $ip = trim($ip);
238 -
239 - // ✅ Valida IP singoli
240 - if (filter_var($ip, FILTER_VALIDATE_IP)) {
241 - continue;
216 + if (!filter_var($ip, FILTER_VALIDATE_IP)) {
217 + return false;
242 218 }
243 -
244 - // ✅ Valida subnet CIDR (es. 1.1.1.1/20)
245 - if (preg_match('/^(\d{1,3}\.){3}\d{1,3}\/\d{1,2}$/', $ip)) {
246 - list($subnet, $mask) = explode('/', $ip);
247 - if (filter_var($subnet, FILTER_VALIDATE_IP) && $mask >= 0 && $mask <= 32) {
248 - continue;
249 - }
250 - }
251 -
252 - // ✅ Valida range IP (es. 1.1.0.0 - 1.1.0.255)
253 - if (preg_match('/^(\d{1,3}\.){3}\d{1,3}\s*-\s*(\d{1,3}\.){3}\d{1,3}$/', $ip)) {
254 - list($start_ip, $end_ip) = array_map('trim', explode('-', $ip));
255 - if (filter_var($start_ip, FILTER_VALIDATE_IP) && filter_var($end_ip, FILTER_VALIDATE_IP)) {
256 - continue;
257 - }
258 - }
259 -
260 - // ❌ Se non passa nessuna validazione, ritorna false
261 - return false;
262 219 }
263 -
264 220 return true;
265 221 }
266 -
222 +
267 223 public function send_credentials_email($username, $password) {
268 224 $admin_email = get_option('admin_email');
269 225 $site_url = home_url();
270 226 $plugin_url = 'https://wordpress.org/plugins/easy-basic-authentication/';
@@ -271,30 +227,25 @@
271 227
272 228 $subject = __('Basic Authentication Credentials Updated', 'easy-basic-authentication');
273 229
274 230 $message = '<html><body>';
275 - $message .= '<p>' . __('Hi,', 'easy-basic-authentication') . '</p>';
231 + $message .= '<p>' . __('Hi Admin,', 'easy-basic-authentication') . '</p>';
276 232 $message .= '<p>' . __('The basic authentication credentials for your site have been updated.', 'easy-basic-authentication') . '</p>';
277 - $message .= '<ul style="list-style-type: none; padding-left: 0;">' .
278 - '<li>' . __('Site URL: ', 'easy-basic-authentication') . '<strong>' . esc_url($site_url) . '</strong></li>' .
279 - '<li>' . __('Username: ', 'easy-basic-authentication') . '<strong>' . esc_html($username) . '</strong></li>' .
280 - '<li>' . __('Password: ', 'easy-basic-authentication') . '<strong>' . __('[updated — not shown for security]', 'easy-basic-authentication') . '</strong></li>' .
281 - '</ul>';
233 + $message .= '<p><ul>
234 + <li>' . __('Site URL: ', 'easy-basic-authentication') . esc_url($site_url) . '</li>
235 + <li>' . __('Username: ', 'easy-basic-authentication') . esc_html($username) . '</li>
236 + <li>' . __('Password: ', 'easy-basic-authentication') . esc_html($password) . '</li>
237 + </ul></p>';
238 + $message .= '<p>' . __('Please ensure to update your records accordingly and keep this information secure.', 'easy-basic-authentication') . '</p>';
282 239 $message .= '<p>' . sprintf(
283 - /* translators: tag "a" and link */
284 - __('For more information about this plugin, visit: %s', 'easy-basic-authentication'),
285 - '<a href="' . esc_url($plugin_url) . '">' . esc_url($plugin_url) . '</a>'
286 - ) . '</p>';
240 + /* translators: %s is the URL of the plugin */
241 + __('For more information about this plugin, visit: %s', 'easy-basic-authentication'), esc_url($plugin_url)) . '</p>';
242 + $message .= '<p>' . __('If you did not make this change or believe this is an error, please contact support immediately.', 'easy-basic-authentication') . '</p>';
287 243 $message .= '<p>' . __('Grazie and buona giornata,', 'easy-basic-authentication') . '</p>';
288 244 $message .= '<p>' . __('The Easy Basic Authentication Plugin Team', 'easy-basic-authentication') . '</p>';
289 245 $message .= '</body></html>';
246 +
290 247
291 - $headers = array(
292 - 'Content-Type: text/html; charset=UTF-8',
293 - 'From: ' . $admin_email,
294 - );
295 -
296 - wp_mail($admin_email, $subject, $message, $headers);
248 + wp_mail($admin_email, $subject, $message);
297 249 }
298 -
299 250
300 251 }