Code Duplication    Length = 24-26 lines in 2 locations

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

@@ 387-412 (lines=26) @@
384
	 *
385
	 * @return bool does the test pass?
386
	 */
387
	protected function test_not_same_as_other_user_data( $password, $strings_to_test ) {
388
		if ( empty( $strings_to_test ) ) {
389
			return false;
390
		}
391
392
		$password_lowercase = strtolower( $password );
393
394
		foreach ( $strings_to_test as $string ) {
395
			$string          = strtolower( $string );
396
			$string_reversed = strrev( $string );
397
398
			if ( $password_lowercase === $string || $password_lowercase === $string_reversed ) {
399
				return false;
400
			}
401
402
			// Also check for the string or reversed string with any numbers just stuck to the end to catch things like bob123 as passwords.
403
			if (
404
				preg_match( '/^' . preg_quote( $string, '/' ) . '\d+$/', $password_lowercase )
405
				|| preg_match( '/^' . preg_quote( $string_reversed, '/' ) . '\d+$/', $password_lowercase )
406
			) {
407
				return false;
408
			}
409
		}
410
411
		return true;
412
	}
413
414
	/**
415
	 * 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.