summaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/lib/Controller/UsersController.php
diff options
context:
space:
mode:
authorDaniel Kesselberg <mail@danielkesselberg.de>2020-08-09 16:36:19 +0200
committerDaniel Kesselberg <mail@danielkesselberg.de>2020-08-09 18:38:19 +0200
commitc19bdb05e8cf24317d6ea3a58951a4e0102b2e70 (patch)
tree7b417e7328f479973615da2a8e2f9f203acb7cbc /apps/provisioning_api/lib/Controller/UsersController.php
parent3db61c43abf5b034e7850f87b122524ab24aeb66 (diff)
downloadnextcloud-server-c19bdb05e8cf24317d6ea3a58951a4e0102b2e70.tar.gz
nextcloud-server-c19bdb05e8cf24317d6ea3a58951a4e0102b2e70.zip
Generate password on addUser by password_policy app
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'apps/provisioning_api/lib/Controller/UsersController.php')
-rw-r--r--apps/provisioning_api/lib/Controller/UsersController.php23
1 files changed, 19 insertions, 4 deletions
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php
index 6e8613085d0..570a02f780d 100644
--- a/apps/provisioning_api/lib/Controller/UsersController.php
+++ b/apps/provisioning_api/lib/Controller/UsersController.php
@@ -59,6 +59,8 @@ use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Security\ISecureRandom;
+use OCP\Security\Events\GenerateSecurePasswordEvent;
+use OCP\EventDispatcher\IEventDispatcher;
class UsersController extends AUserData {
@@ -76,6 +78,8 @@ class UsersController extends AUserData {
private $secureRandom;
/** @var RemoteWipe */
private $remoteWipe;
+ /** @var IEventDispatcher */
+ private $eventDispatcher;
public function __construct(string $appName,
IRequest $request,
@@ -90,7 +94,8 @@ class UsersController extends AUserData {
NewUserMailHelper $newUserMailHelper,
FederatedShareProviderFactory $federatedShareProviderFactory,
ISecureRandom $secureRandom,
- RemoteWipe $remoteWipe) {
+ RemoteWipe $remoteWipe,
+ IEventDispatcher $eventDispatcher) {
parent::__construct($appName,
$request,
$userManager,
@@ -107,6 +112,7 @@ class UsersController extends AUserData {
$this->federatedShareProviderFactory = $federatedShareProviderFactory;
$this->secureRandom = $secureRandom;
$this->remoteWipe = $remoteWipe;
+ $this->eventDispatcher = $eventDispatcher;
}
/**
@@ -286,9 +292,18 @@ class UsersController extends AUserData {
throw new OCSException('To send a password link to the user an email address is required.', 108);
}
- $password = $this->secureRandom->generate(10);
- // Make sure we pass the password_policy
- $password .= $this->secureRandom->generate(2, '$!.,;:-~+*[]{}()');
+ $passwordEvent = new GenerateSecurePasswordEvent();
+ $this->eventDispatcher->dispatchTyped($passwordEvent);
+
+ $password = $passwordEvent->getPassword();
+ if ($password === null) {
+ // Fallback: ensure to pass password_policy in any case
+ $password = $this->secureRandom->generate(10)
+ . $this->secureRandom->generate(1, ISecureRandom::CHAR_UPPER)
+ . $this->secureRandom->generate(1, ISecureRandom::CHAR_LOWER)
+ . $this->secureRandom->generate(1, ISecureRandom::CHAR_DIGITS)
+ . $this->secureRandom->generate(1, ISecureRandom::CHAR_SYMBOLS);
+ }
$generatePasswordResetToken = true;
}