@@ 219-286 (lines=68) @@ | ||
216 | * @param array $sections only return specific sections with the passed keys, defaults to all. |
|
217 | * @return array test descriptions. |
|
218 | */ |
|
219 | protected function list_tests( $sections = false ) { |
|
220 | // Note: these should be in order of priority. |
|
221 | $tests = array( |
|
222 | 'preg_match' => array( |
|
223 | 'no_backslashes' => array( |
|
224 | 'pattern' => '^[^\\\\]*$', |
|
225 | 'error' => __( 'Passwords may not contain the character "\".', 'jetpack' ), |
|
226 | 'required' => true, |
|
227 | 'fail_immediately' => true, |
|
228 | ), |
|
229 | 'minimum_length' => array( |
|
230 | 'pattern' => '^.{' . $this->min_password_length . ',}', |
|
231 | /* translators: %d is a number of characters in the password. */ |
|
232 | 'error' => sprintf( __( 'Password must be at least %d characters.', 'jetpack' ), $this->min_password_length ), |
|
233 | 'required' => true, |
|
234 | 'fail_immediately' => true, |
|
235 | ), |
|
236 | 'has_mixed_case' => array( |
|
237 | 'pattern' => '([a-z].*?[A-Z]|[A-Z].*?[a-z])', |
|
238 | 'error' => __( 'This password is too easy to guess: you can improve it by adding additional uppercase letters, lowercase letters, or numbers.', 'jetpack' ), |
|
239 | 'trim' => true, |
|
240 | 'required' => false, |
|
241 | ), |
|
242 | 'has_digit' => array( |
|
243 | 'pattern' => '\d', |
|
244 | 'error' => __( 'This password is too easy to guess: you can improve it by mixing both letters and numbers.', 'jetpack' ), |
|
245 | 'trim' => false, |
|
246 | 'required' => false, |
|
247 | ), |
|
248 | 'has_special_char' => array( |
|
249 | 'pattern' => '[^a-zA-Z\d]', |
|
250 | 'error' => __( 'This password is too easy to guess: you can improve it by including special characters such as !#=?*&.', 'jetpack' ), |
|
251 | 'required' => false, |
|
252 | ), |
|
253 | ), |
|
254 | 'compare_to_list' => array( |
|
255 | 'not_a_common_password' => array( |
|
256 | 'list_callback' => 'get_common_passwords', |
|
257 | 'compare_callback' => 'negative_in_array', |
|
258 | 'error' => __( 'This is a very common password. Choose something that will be harder for others to guess.', 'jetpack' ), |
|
259 | 'required' => true, |
|
260 | ), |
|
261 | 'not_same_as_other_user_data' => array( |
|
262 | 'list_callback' => 'get_other_user_data', |
|
263 | 'compare_callback' => 'test_not_same_as_other_user_data', |
|
264 | 'error' => __( 'Your password is too weak: Looks like you\'re including easy to guess information about yourself. Try something a little more unique.', 'jetpack' ), |
|
265 | 'required' => true, |
|
266 | ), |
|
267 | ), |
|
268 | ); |
|
269 | ||
270 | /** |
|
271 | * Filters Jetpack's password strength enforcement settings. You can determine the tests run |
|
272 | * and their order based on whatever criteria you wish to specify. |
|
273 | * |
|
274 | * @since 7.2.0 |
|
275 | * |
|
276 | * @param array $minimum_entropy_bits minimum entropy bits requirement. |
|
277 | */ |
|
278 | $tests = apply_filters( 'jetpack_password_checker_tests', $tests ); |
|
279 | ||
280 | if ( ! $sections ) { |
|
281 | return $tests; |
|
282 | } |
|
283 | ||
284 | $sections = (array) $sections; |
|
285 | return array_intersect_key( $tests, array_flip( $sections ) ); |
|
286 | } |
|
287 | ||
288 | /** |
|
289 | * Provides the regular expression tester functionality. |
@@ 227-294 (lines=68) @@ | ||
224 | * @param array $sections only return specific sections with the passed keys, defaults to all. |
|
225 | * @return array test descriptions. |
|
226 | */ |
|
227 | protected function list_tests( $sections = false ) { |
|
228 | // Note: these should be in order of priority. |
|
229 | $tests = array( |
|
230 | 'preg_match' => array( |
|
231 | 'no_backslashes' => array( |
|
232 | 'pattern' => '^[^\\\\]*$', |
|
233 | 'error' => __( 'Passwords may not contain the character "\".', 'jetpack' ), |
|
234 | 'required' => true, |
|
235 | 'fail_immediately' => true, |
|
236 | ), |
|
237 | 'minimum_length' => array( |
|
238 | 'pattern' => '^.{' . $this->min_password_length . ',}', |
|
239 | /* translators: %d is a number of characters in the password. */ |
|
240 | 'error' => sprintf( __( 'Password must be at least %d characters.', 'jetpack' ), $this->min_password_length ), |
|
241 | 'required' => true, |
|
242 | 'fail_immediately' => true, |
|
243 | ), |
|
244 | 'has_mixed_case' => array( |
|
245 | 'pattern' => '([a-z].*?[A-Z]|[A-Z].*?[a-z])', |
|
246 | 'error' => __( 'This password is too easy to guess: you can improve it by adding additional uppercase letters, lowercase letters, or numbers.', 'jetpack' ), |
|
247 | 'trim' => true, |
|
248 | 'required' => false, |
|
249 | ), |
|
250 | 'has_digit' => array( |
|
251 | 'pattern' => '\d', |
|
252 | 'error' => __( 'This password is too easy to guess: you can improve it by mixing both letters and numbers.', 'jetpack' ), |
|
253 | 'trim' => false, |
|
254 | 'required' => false, |
|
255 | ), |
|
256 | 'has_special_char' => array( |
|
257 | 'pattern' => '[^a-zA-Z\d]', |
|
258 | 'error' => __( 'This password is too easy to guess: you can improve it by including special characters such as !#=?*&.', 'jetpack' ), |
|
259 | 'required' => false, |
|
260 | ), |
|
261 | ), |
|
262 | 'compare_to_list' => array( |
|
263 | 'not_a_common_password' => array( |
|
264 | 'list_callback' => 'get_common_passwords', |
|
265 | 'compare_callback' => 'negative_in_array', |
|
266 | 'error' => __( 'This is a very common password. Choose something that will be harder for others to guess.', 'jetpack' ), |
|
267 | 'required' => true, |
|
268 | ), |
|
269 | 'not_same_as_other_user_data' => array( |
|
270 | 'list_callback' => 'get_other_user_data', |
|
271 | 'compare_callback' => 'test_not_same_as_other_user_data', |
|
272 | 'error' => __( 'Your password is too weak: Looks like you\'re including easy to guess information about yourself. Try something a little more unique.', 'jetpack' ), |
|
273 | 'required' => true, |
|
274 | ), |
|
275 | ), |
|
276 | ); |
|
277 | ||
278 | /** |
|
279 | * Filters Jetpack's password strength enforcement settings. You can determine the tests run |
|
280 | * and their order based on whatever criteria you wish to specify. |
|
281 | * |
|
282 | * @since 7.2.0 |
|
283 | * |
|
284 | * @param array $minimum_entropy_bits minimum entropy bits requirement. |
|
285 | */ |
|
286 | $tests = apply_filters( 'jetpack_password_checker_tests', $tests ); |
|
287 | ||
288 | if ( ! $sections ) { |
|
289 | return $tests; |
|
290 | } |
|
291 | ||
292 | $sections = (array) $sections; |
|
293 | return array_intersect_key( $tests, array_flip( $sections ) ); |
|
294 | } |
|
295 | ||
296 | /** |
|
297 | * Provides the regular expression tester functionality. |