| @@ 132-169 (lines=38) @@ | ||
| 129 | * @param Boolean $required_only only test against required conditions, defaults to false. |
|
| 130 | * @return array $results an array containing failed and passed test results. |
|
| 131 | */ |
|
| 132 | public function test( $password, $required_only = false ) { |
|
| 133 | ||
| 134 | $this->password = $password; |
|
| 135 | $results = $this->run_tests( $this->list_tests(), $required_only ); |
|
| 136 | ||
| 137 | // If we've failed on the required tests, return now. |
|
| 138 | if ( ! empty( $results['failed'] ) ) { |
|
| 139 | return array( |
|
| 140 | 'passed' => false, |
|
| 141 | 'test_results' => $results, |
|
| 142 | ); |
|
| 143 | } |
|
| 144 | ||
| 145 | /** |
|
| 146 | * Filters Jetpack's password strength enforcement settings. You can modify the minimum |
|
| 147 | * entropy bits requirement using this filter. |
|
| 148 | * |
|
| 149 | * @since 7.2.0 |
|
| 150 | * |
|
| 151 | * @param array $minimum_entropy_bits minimum entropy bits requirement. |
|
| 152 | */ |
|
| 153 | $bits = apply_filters( 'jetpack_password_checker_minimum_entropy_bits', self::MINIMUM_BITS ); |
|
| 154 | $entropy_bits = $this->calculate_entropy_bits( $this->password ); |
|
| 155 | ||
| 156 | // If we have failed the entropy bits test, run the regex tests so we can suggest improvements. |
|
| 157 | if ( $entropy_bits < $bits ) { |
|
| 158 | $results['failed']['entropy_bits'] = $entropy_bits; |
|
| 159 | $results = array_merge( |
|
| 160 | $results, |
|
| 161 | $this->run_tests( $this->list_tests( 'preg_match' ), false ) |
|
| 162 | ); |
|
| 163 | } |
|
| 164 | ||
| 165 | return( array( |
|
| 166 | 'passed' => empty( $results['failed'] ), |
|
| 167 | 'test_results' => $results, |
|
| 168 | ) ); |
|
| 169 | } |
|
| 170 | ||
| 171 | /** |
|
| 172 | * Run the tests using the currently set up object values. |
|
| @@ 130-167 (lines=38) @@ | ||
| 127 | * @param Boolean $required_only only test against required conditions, defaults to false. |
|
| 128 | * @return array $results an array containing failed and passed test results. |
|
| 129 | */ |
|
| 130 | public function test( $password, $required_only = false ) { |
|
| 131 | ||
| 132 | $this->password = $password; |
|
| 133 | $results = $this->run_tests( $this->list_tests(), $required_only ); |
|
| 134 | ||
| 135 | // If we've failed on the required tests, return now. |
|
| 136 | if ( ! empty( $results['failed'] ) ) { |
|
| 137 | return array( |
|
| 138 | 'passed' => false, |
|
| 139 | 'test_results' => $results, |
|
| 140 | ); |
|
| 141 | } |
|
| 142 | ||
| 143 | /** |
|
| 144 | * Filters Jetpack's password strength enforcement settings. You can modify the minimum |
|
| 145 | * entropy bits requirement using this filter. |
|
| 146 | * |
|
| 147 | * @since 7.2.0 |
|
| 148 | * |
|
| 149 | * @param array $minimum_entropy_bits minimum entropy bits requirement. |
|
| 150 | */ |
|
| 151 | $bits = apply_filters( 'jetpack_password_checker_minimum_entropy_bits', self::MINIMUM_BITS ); |
|
| 152 | $entropy_bits = $this->calculate_entropy_bits( $this->password ); |
|
| 153 | ||
| 154 | // If we have failed the entropy bits test, run the regex tests so we can suggest improvements. |
|
| 155 | if ( $entropy_bits < $bits ) { |
|
| 156 | $results['failed']['entropy_bits'] = $entropy_bits; |
|
| 157 | $results = array_merge( |
|
| 158 | $results, |
|
| 159 | $this->run_tests( $this->list_tests( 'preg_match' ), false ) |
|
| 160 | ); |
|
| 161 | } |
|
| 162 | ||
| 163 | return( array( |
|
| 164 | 'passed' => empty( $results['failed'] ), |
|
| 165 | 'test_results' => $results, |
|
| 166 | ) ); |
|
| 167 | } |
|
| 168 | ||
| 169 | /** |
|
| 170 | * Run the tests using the currently set up object values. |
|