Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
hotpalgorithm.php
1<?php
2
4
9
10Loc::loadMessages(__FILE__);
11
13{
14 const SYNC_WINDOW = 15000;
15 protected static $type = 'hotp';
16 protected $window = 10;
17
18 public function __construct()
19 {
20 $window = (int)Option::get('security', 'hotp_user_window', 10);
21 if ($window && $window > 0)
22 {
23 $this->window = $window;
24 }
25 }
26
30 public function verify($input, $params = null)
31 {
32 $input = (string)$input;
33
34 if (!preg_match('#^\d+$#D', $input))
35 {
36 throw new ArgumentOutOfRangeException('input', 'string with numbers');
37 }
38
39 $counter = (int)$params;
40 $result = false;
42 while ($window--)
43 {
44 if ($this->isStringsEqual($input, $this->generateOTP($counter)))
45 {
46 $result = true;
47 break;
48 }
49 $counter++;
50 }
51
52 if ($result === true)
53 {
54 return [true, $counter + 1];
55 }
56
57 return [false, null];
58 }
59
63 public function generateUri($label, array $opts = [])
64 {
65 $opts += ['counter' => 1];
66 return parent::generateUri($label, $opts);
67 }
68
72 public function getSyncParameters($inputA, $inputB)
73 {
74 $counter = 0;
75 $this->window = 1;
76 for ($i = 0; $i < self::SYNC_WINDOW; $i++)
77 {
78 [$verifyA,] = $this->verify($inputA, $counter);
79 [$verifyB,] = $this->verify($inputB, $counter + 1);
80 $counter++;
81 if ($verifyA && $verifyB)
82 {
83 break;
84 }
85 }
86
87 if ($i === self::SYNC_WINDOW)
88 {
89 throw new OtpException('Cannot synchronize this secret key with the provided password values.');
90 }
91
92 return $counter;
93 }
94}
static loadMessages($file)
Definition loc.php:64