1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* File:LegacyAuthentication.php |
6
|
|
|
* |
7
|
|
|
* @author Maciej Sławik <[email protected]> |
8
|
|
|
* @copyright Copyright (C) 2018 Lizard Media (http://lizardmedia.pl) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace LizardMedia\PasswordMigrator\Model; |
12
|
|
|
|
13
|
|
|
use Exception; |
14
|
|
|
use LizardMedia\PasswordMigrator\Api\Data\PasswordRepositoryInterface; |
15
|
|
|
use LizardMedia\PasswordMigrator\Api\LegacyAuthenticationInterface; |
16
|
|
|
use LizardMedia\PasswordMigrator\Api\LegacyEncryptorInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class LegacyAuthentication |
20
|
|
|
* @package LizardMedia\PasswordMigrator\Model |
21
|
|
|
*/ |
22
|
|
|
class LegacyAuthentication implements LegacyAuthenticationInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var PasswordRepositoryInterface |
26
|
|
|
*/ |
27
|
|
|
private $passwordRepository; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var LegacyEncryptorInterface |
31
|
|
|
*/ |
32
|
|
|
private $legacyEncryptor; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* LegacyAuthentication constructor. |
36
|
|
|
* @param PasswordRepositoryInterface $passwordRepository |
37
|
|
|
* @param LegacyEncryptorInterface $legacyEncryptor |
38
|
|
|
*/ |
39
|
|
|
public function __construct( |
40
|
|
|
PasswordRepositoryInterface $passwordRepository, |
41
|
|
|
LegacyEncryptorInterface $legacyEncryptor |
42
|
|
|
) { |
43
|
|
|
$this->passwordRepository = $passwordRepository; |
44
|
|
|
$this->legacyEncryptor = $legacyEncryptor; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param int $customerId |
49
|
|
|
* @param string $password |
50
|
|
|
* @return bool |
51
|
|
|
*/ |
52
|
|
|
public function canLegacyAuthenticate(int $customerId, string $password): bool |
53
|
|
|
{ |
54
|
|
|
try { |
55
|
|
|
$passwordDTO = $this->passwordRepository->getByCustomerId($customerId); |
56
|
|
|
$legacyHash = $this->legacyEncryptor->encrypt($password, $passwordDTO->getSalt()); |
57
|
|
|
return $legacyHash === $passwordDTO->getPassword(); |
58
|
|
|
} catch (Exception $e) { |
59
|
|
|
return false; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|