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