1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Sujith Haridasan <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2018, ownCloud GmbH |
6
|
|
|
* @license AGPL-3.0 |
7
|
|
|
* |
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
10
|
|
|
* as published by the Free Software Foundation. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace OC\User\Service; |
23
|
|
|
|
24
|
|
|
use OCP\Security\ISecureRandom; |
25
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
26
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent; |
27
|
|
|
|
28
|
|
|
class CreatePassword { |
29
|
|
|
/** @var EventDispatcherInterface */ |
30
|
|
|
private $eventDispatcher; |
31
|
|
|
/** @var ISecureRandom */ |
32
|
|
|
private $secureRandom; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* CreatePassword constructor. |
36
|
|
|
* |
37
|
|
|
* @param EventDispatcherInterface $eventDispatcher |
38
|
|
|
*/ |
39
|
|
|
public function __construct(EventDispatcherInterface $eventDispatcher, ISecureRandom $secureRandom) { |
40
|
|
|
$this->eventDispatcher = $eventDispatcher; |
41
|
|
|
$this->secureRandom = $secureRandom; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Create password |
46
|
|
|
* |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public function createPassword() { |
50
|
|
|
$event = new GenericEvent(); |
51
|
|
|
$this->eventDispatcher->dispatch('OCP\User::createPassword', $event); |
52
|
|
|
if ($event->hasArgument('password')) { |
53
|
|
|
$password = $event->getArgument('password'); |
54
|
|
|
} else { |
55
|
|
|
$password = $this->secureRandom->generate(20); |
56
|
|
|
} |
57
|
|
|
return $password; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|