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
defender-security / src / component / altcha / class-challenge-options.php

class-challenge-options.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at src/component/altcha/class-challenge-options.php

50 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class Challenge_Options
4 *
5 * @package WP_Defender\Component\Altcha
6 */
7
8 namespace WP_Defender\Component\Altcha;
9
10 use WP_Defender\Component\Altcha\Hasher\Algorithm;
11 use WP_Defender\Component\Crypt;
12
13 /**
14 * Class Challenge_Options.
15 *
16 * @phpstan-import-type ChallengeParams from Base_Challenge_Options
17 */
18 class Challenge_Options extends Base_Challenge_Options {
19 private const DEFAULT_SALT_LENGTH = 12;
20
21 /**
22 * Options for creation of a new challenge with sane defaults.
23 *
24 * @param string $algorithm Hashing algorithm to use (`SHA-1`, `SHA-256`, `SHA-512`, default:
25 * `SHA-256`).
26 * @param int $max_number Maximum number for the random number generator (default: 1,000,000).
27 * @param null|\DateTimeInterface $expires Optional expiration time for the challenge.
28 * @param array $params Optional URL-encoded query parameters.
29 * @param int $salt_length Length of the random salt (default: 12 bytes).
30 */
31 public function __construct(
32 string $algorithm = Algorithm::SHA256,
33 int $max_number = self::DEFAULT_MAX_NUMBER,
34 ?\DateTimeInterface $expires = null,
35 array $params = array(),
36 int $salt_length = self::DEFAULT_SALT_LENGTH
37 ) {
38 $salt_length = max( self::DEFAULT_SALT_LENGTH, $salt_length );
39
40 parent::__construct(
41 $algorithm,
42 $max_number,
43 $expires,
44 bin2hex( Crypt::random_bytes( $salt_length ) ),
45 Crypt::random_int( 0, $max_number ),
46 $params
47 );
48 }
49 }
50