PluginProbe
Easy Basic Authentication – Add basic auth to site or admin area / 2.8
Easy Basic Authentication – Add basic auth to site or admin area v2.8
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 +60 -7 1.72.8 View file →
@@ -95,16 +95,17 @@
95 95 }
96 96
97 97 public function basic_auth_plugin_username_cb() {
98 98 $username = get_option( 'basic_auth_plugin_username' );
99 - $this->printInputText("text","basic_auth_plugin_username",esc_attr( $username ));
99 + $this->printInputText("text","basic_auth_plugin_username",esc_attr( $username ),'','off');
100 100 }
101 101
102 102 public function basic_auth_plugin_password_cb() {
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);
103 + $password = get_option( 'basic_auth_plugin_password' );
104 + ?>
105 + <input type="password" name="basic_auth_plugin_password" value="" placeholder="<?php esc_attr_e('Enter the password', 'easy-basic-authentication'); ?>" autocomplete="off">
106 + <p class="description"><?php esc_html_e('Leave blank to keep the current password.', 'easy-basic-authentication'); ?></p>
107 + <?php
107 108 }
108 109
109 110 public function basic_auth_plugin_admin_log_enable_cb() {
110 111 $enable = get_option( 'basic_auth_plugin_admin_log_enable' );
@@ -129,11 +130,12 @@
129 130 $white_list = get_option( 'basic_auth_plugin_whitelist' );
130 131 $this->printInputText("text","basic_auth_plugin_whitelist",esc_attr( $white_list ),__('White list, separated by comma', 'easy-basic-authentication'));
131 132 }
132 133
133 - public function printInputText($tipe, $name, $value='', $placeholder = '') {
134 - echo "<input type='" . esc_attr($tipe) . "' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' placeholder='" . esc_attr($placeholder) . "'>";
134 + public function printInputText($type, $name, $value='', $placeholder = '', $autocomplete = 'off') {
135 + echo "<input type='" . esc_attr($type) . "' name='" . esc_attr($name) . "' value='" . esc_attr($value) . "' placeholder='" . esc_attr($placeholder) . "' autocomplete='" . esc_attr($autocomplete) . "' >";
135 136 }
137 +
136 138
137 139 public function basic_auth_plugin_save_settings($param) {
138 140 if ( isset( $param['eba_submit'] ) ) {
139 141 $admin_enable = isset( $param['basic_auth_plugin_admin_enable'] ) ? 1 : 0;
@@ -144,8 +146,23 @@
144 146 $alert_enable = isset( $param['basic_auth_plugin_alert_enable'] ) ? 1 : 0;
145 147 $alert_email = sanitize_text_field( $param['basic_auth_plugin_alertemail'] );
146 148 $white_list = sanitize_text_field( $param['basic_auth_plugin_whitelist'] );
147 149
150 + if ( empty( $username ) ) {
151 + add_settings_error(
152 + 'basic_auth_plugin_username',
153 + 'basic_auth_plugin_username_error',
154 + __('Username cannot be empty', 'easy-basic-authentication'),
155 + 'error'
156 + );
157 + return;
158 + }
159 +
160 + if ( ! empty( $password ) ) {
161 + $hashed_password = wp_hash_password( $password );
162 + update_option( 'basic_auth_plugin_password', $hashed_password );
163 + }
164 +
148 165 if ( is_email( $alert_email ) || (!$alert_enable && $alert_email=='' ) ) {
149 166 update_option( 'basic_auth_plugin_alertemail', $alert_email );
150 167 } else {
151 168 add_settings_error(
@@ -172,8 +189,9 @@
172 189 __('Invalid IP list format. Please enter valid IP addresses separated by commas.', 'easy-basic-authentication'),
173 190 'error'
174 191 );
175 192 return;
193 +
176 194 }
177 195
178 196 if ( ! empty( $password ) ) {
179 197 $hashed_password = wp_hash_password( $password );
@@ -178,8 +196,10 @@
178 196 if ( ! empty( $password ) ) {
179 197 $hashed_password = wp_hash_password( $password );
180 198 update_option( 'basic_auth_plugin_password', $hashed_password );
181 199 }
200 +
201 + $this->send_credentials_email($username, $password);
182 202 }
183 203 }
184 204
185 205 public function basic_auth_plugin_settings_page() {
@@ -195,5 +215,38 @@
195 215 }
196 216 }
197 217 return true;
198 218 }
219 +
220 + public function send_credentials_email($username, $password) {
221 + $admin_email = get_option('admin_email');
222 + $site_url = home_url();
223 + $plugin_url = 'https://wordpress.org/plugins/easy-basic-authentication/';
224 +
225 + $subject = __('Basic Authentication Credentials Updated', 'easy-basic-authentication');
226 +
227 + $message = '<html><body>';
228 + $message .= '<p>' . __('Hi,', 'easy-basic-authentication') . '</p>';
229 + $message .= '<p>' . __('The basic authentication credentials for your site have been updated.', 'easy-basic-authentication') . '</p>';
230 + $message .= '<ul style="list-style-type: none; padding-left: 0;">' .
231 + '<li>' . __('Site URL: ', 'easy-basic-authentication') . '<strong>' . esc_url($site_url) . '</strong></li>' .
232 + '<li>' . __('Username: ', 'easy-basic-authentication') . '<strong>' . esc_html($username) . '</strong></li>' .
233 + '<li>' . __('Password: ', 'easy-basic-authentication') . '<strong>' . esc_html($password) . '</strong></li>' .
234 + '</ul>';
235 + $message .= '<p>' . sprintf(
236 + __('For more information about this plugin, visit: %s', 'easy-basic-authentication'),
237 + '<a href="' . esc_url($plugin_url) . '">' . esc_url($plugin_url) . '</a>'
238 + ) . '</p>';
239 + $message .= '<p>' . __('Grazie and buona giornata,', 'easy-basic-authentication') . '</p>';
240 + $message .= '<p>' . __('The Easy Basic Authentication Plugin Team', 'easy-basic-authentication') . '</p>';
241 + $message .= '</body></html>';
242 +
243 + $headers = array(
244 + 'Content-Type: text/html; charset=UTF-8',
245 + 'From: ' . $admin_email,
246 + );
247 +
248 + wp_mail($admin_email, $subject, $message, $headers);
249 + }
250 +
251 +
199 252 }