1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_auth_forms\Rules; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_accounts\Interfaces\ICert; |
7
|
|
|
use kalanis\kw_accounts\Interfaces\IUser; |
8
|
|
|
use kalanis\kw_auth_sources\Interfaces\IStatus; |
9
|
|
|
use kalanis\kw_rules\Exceptions\RuleException; |
10
|
|
|
use kalanis\kw_rules\Interfaces\IValidate; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class ImplodeHash |
15
|
|
|
* @package kalanis\kw_auth_forms\Rules |
16
|
|
|
* Check digest value for preselected inputs - validate hash |
17
|
|
|
*/ |
18
|
|
|
class ImplodeHash extends ARule |
19
|
|
|
{ |
20
|
|
|
protected IUser $userSource; |
21
|
|
|
protected ICert $certSource; |
22
|
|
|
protected IStatus $libStatus; |
23
|
|
|
protected string $glue = ''; |
24
|
|
|
protected string $algorithm = ''; |
25
|
|
|
|
26
|
14 |
|
public function __construct(IUser $userSource, ICert $certSource, IStatus $libStatus, string $glue = '|', string $algorithm = 'md5') |
27
|
|
|
{ |
28
|
14 |
|
$this->userSource = $userSource; |
29
|
14 |
|
$this->certSource = $certSource; |
30
|
14 |
|
$this->libStatus = $libStatus; |
31
|
14 |
|
$this->glue = $glue; |
32
|
14 |
|
$this->algorithm = $algorithm; |
33
|
14 |
|
} |
34
|
|
|
|
35
|
14 |
|
public function validate(IValidate $entry): void |
36
|
|
|
{ |
37
|
14 |
|
if (!$this->libStatus->allowCert($this->userSource->getStatus())) { |
38
|
4 |
|
throw new RuleException($this->errorText); |
39
|
|
|
} |
40
|
10 |
|
$col = implode($this->glue, $this->sentInputs() + [$this->certSource->getSalt()]); |
41
|
10 |
|
if (hash($this->algorithm, $col) != strval($entry->getValue())) { |
42
|
3 |
|
throw new RuleException($this->errorText); |
43
|
|
|
} |
44
|
7 |
|
} |
45
|
|
|
} |
46
|
|
|
|