Code Duplication    Length = 24-24 lines in 2 locations

projects/packages/password-checker/src/class-password-checker.php 1 location

@@ 395-418 (lines=24) @@
392
	 * @param array  $strings_to_test known user data.
393
	 * @return Boolean does the test pass?
394
	 */
395
	protected function test_not_same_as_other_user_data( $password, $strings_to_test ) {
396
		$password_lowercase = strtolower( $password );
397
		foreach ( array_unique( $strings_to_test ) as $string ) {
398
			if ( empty( $string ) ) {
399
				continue;
400
			}
401
402
			$string          = strtolower( $string );
403
			$string_reversed = strrev( $string );
404
405
			if ( $password_lowercase === $string || $password_lowercase === $string_reversed ) {
406
				return false;
407
			}
408
409
			// Also check for the string or reversed string with any numbers just stuck to the end to catch things like bob123 as passwords.
410
			if (
411
				preg_match( '/^' . preg_quote( $string, '/' ) . '\d+$/', $password_lowercase )
412
				|| preg_match( '/^' . preg_quote( $string_reversed, '/' ) . '\d+$/', $password_lowercase )
413
			) {
414
				return false;
415
			}
416
		}
417
		return true;
418
	}
419
420
	/**
421
	 * A shorthand for the not in array construct.

projects/plugins/jetpack/_inc/lib/class.jetpack-password-checker.php 1 location

@@ 383-406 (lines=24) @@
380
	 * @param array  $strings_to_test known user data.
381
	 * @return Boolean does the test pass?
382
	 */
383
	protected function test_not_same_as_other_user_data( $password, $strings_to_test ) {
384
		$password_lowercase = strtolower( $password );
385
		foreach ( array_unique( $strings_to_test ) as $string ) {
386
			if ( empty( $string ) ) {
387
				continue;
388
			}
389
390
			$string          = strtolower( $string );
391
			$string_reversed = strrev( $string );
392
393
			if ( $password_lowercase === $string || $password_lowercase === $string_reversed ) {
394
				return false;
395
			}
396
397
			// Also check for the string or reversed string with any numbers just stuck to the end to catch things like bob123 as passwords.
398
			if (
399
				preg_match( '/^' . preg_quote( $string, '/' ) . '\d+$/', $password_lowercase )
400
				|| preg_match( '/^' . preg_quote( $string_reversed, '/' ) . '\d+$/', $password_lowercase )
401
			) {
402
				return false;
403
			}
404
		}
405
		return true;
406
	}
407
408
	/**
409
	 * A shorthand for the not in array construct.