|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* sysPass |
|
4
|
|
|
* |
|
5
|
|
|
* @author nuxsmin |
|
6
|
|
|
* @link https://syspass.org |
|
7
|
|
|
* @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org |
|
8
|
|
|
* |
|
9
|
|
|
* This file is part of sysPass. |
|
10
|
|
|
* |
|
11
|
|
|
* sysPass is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU General Public License as published by |
|
13
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
14
|
|
|
* (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* sysPass is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU General Public License |
|
22
|
|
|
* along with sysPass. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace SP\Services\Account; |
|
26
|
|
|
|
|
27
|
|
|
use SP\Config\ConfigData; |
|
28
|
|
|
use SP\Core\Exceptions\ValidationException; |
|
29
|
|
|
use SP\DataModel\ItemPreset\Password; |
|
30
|
|
|
use SP\Mvc\Controller\Validators\PasswordValidator; |
|
31
|
|
|
use SP\Services\ItemPreset\ItemPresetInterface; |
|
32
|
|
|
use SP\Services\ItemPreset\ItemPresetService; |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Class AccountPreset |
|
37
|
|
|
* |
|
38
|
|
|
* @package SP\Services\Account |
|
39
|
|
|
*/ |
|
40
|
|
|
class AccountPresetService |
|
41
|
|
|
{ |
|
42
|
|
|
/** |
|
43
|
|
|
* @var ItemPresetService |
|
44
|
|
|
*/ |
|
45
|
|
|
private $itemPresetService; |
|
46
|
|
|
/** |
|
47
|
|
|
* @var ConfigData |
|
48
|
|
|
*/ |
|
49
|
|
|
private $configData; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* AccountPreset constructor. |
|
53
|
|
|
* |
|
54
|
|
|
* @param ItemPresetService $itemPresetService |
|
55
|
|
|
* @param ConfigData $configData |
|
56
|
|
|
*/ |
|
57
|
|
|
public function __construct(ItemPresetService $itemPresetService, ConfigData $configData) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->itemPresetService = $itemPresetService; |
|
60
|
|
|
$this->configData = $configData; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param AccountRequest $accountRequest |
|
65
|
|
|
* |
|
66
|
|
|
* @throws ValidationException |
|
67
|
|
|
* @throws \SP\Core\Exceptions\ConstraintException |
|
68
|
|
|
* @throws \SP\Core\Exceptions\NoSuchPropertyException |
|
69
|
|
|
* @throws \SP\Core\Exceptions\QueryException |
|
70
|
|
|
*/ |
|
71
|
|
|
public function checkPasswordPreset(AccountRequest $accountRequest) |
|
72
|
|
|
{ |
|
73
|
|
|
$itemPreset = $this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PASSWORD); |
|
74
|
|
|
|
|
75
|
|
|
if ($itemPreset !== null && $itemPreset->getFixed() === 1) { |
|
76
|
|
|
$passwordPreset = $itemPreset->hydrate(Password::class); |
|
77
|
|
|
|
|
78
|
|
|
PasswordValidator::factory($passwordPreset)->validate($accountRequest->pass); |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
if ($this->configData->isAccountExpireEnabled()) { |
|
81
|
|
|
$expireTimePreset = $passwordPreset->getExpireTime(); |
|
82
|
|
|
|
|
83
|
|
|
if ($expireTimePreset > 0 |
|
84
|
|
|
&& ($accountRequest->passDateChange === 0 |
|
85
|
|
|
|| $accountRequest->passDateChange < time() + $expireTimePreset) |
|
86
|
|
|
) { |
|
87
|
|
|
$accountRequest->passDateChange = time() + $expireTimePreset; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
} |