PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
← All changes | src/component/class-altcha-handler.php +18 -12 5.3.1 → 6.3.0 View file →
@@ -6,10 +6,12 @@
6 6 */
7 7
8 8 namespace WP_Defender\Component;
9 9
10 -use AltchaOrg\Altcha\ChallengeOptions;
11 -use AltchaOrg\Altcha\Altcha;
10 +use WP_Defender\Component\Altcha\Challenge;
11 +use WP_Defender\Component\Altcha\Challenge_Options;
12 +use WP_Defender\Component\Altcha\Altcha;
13 +use WP_Defender\Component\Altcha\Hasher\Algorithm;
12 14
13 15 /**
14 16 * Provides methods for creating and verifying Altcha's challenge.
15 17 */
@@ -46,9 +48,9 @@
46 48 */
47 49 private function get_hmac_key() {
48 50 $hmac_key = get_option( self::HMAC_KEY_OPTION_NAME );
49 51
50 - if ( ! $hmac_key ) {
52 + if ( ! is_string( $hmac_key ) || '' === trim( $hmac_key ) ) {
51 53 // Generate a random key if it doesn't exist.
52 54 $hmac_key = wp_generate_password( 64, true, true );
53 55
54 56 update_option( self::HMAC_KEY_OPTION_NAME, $hmac_key );
@@ -61,19 +63,21 @@
61 63 * Create a new ALTCHA challenge.
62 64 *
63 65 * @param int $max_number Maximum random number for the challenge.
64 66 *
65 - * @return array Challenge data.
67 + * @return Challenge Challenge data.
66 68 */
67 - public function create_challenge( $max_number = 100000 ) {
68 - $options = new ChallengeOptions(
69 - array(
70 - 'hmacKey' => $this->hmac_key,
71 - 'maxNumber' => $max_number,
72 - )
69 + public function create_challenge( $max_number = 100000 ): Challenge {
70 + $altcha = new Altcha( $this->hmac_key );
71 +
72 + // Create a new challenge.
73 + $options = new Challenge_Options(
74 + Algorithm::SHA256,
75 + $max_number,
76 + ( new \DateTimeImmutable() )->add( new \DateInterval( 'PT10S' ) )
73 77 );
74 78
75 - return Altcha::createChallenge( $options );
79 + return $altcha->create_challenge( $options );
76 80 }
77 81
78 82 /**
79 83 * Verify the given solution against the challenge.
@@ -83,7 +87,9 @@
83 87 *
84 88 * @return bool Verification result.
85 89 */
86 90 public function verify_solution( array $payload, $strict_mode = true ) {
87 - return Altcha::verifySolution( $payload, $this->hmac_key, $strict_mode );
91 + $altcha = new Altcha( $this->hmac_key );
92 +
93 + return $altcha->verify_solution( $payload, $strict_mode );
88 94 }
89 95 }