aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/Security/Events/GenerateSecurePasswordEvent.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/public/Security/Events/GenerateSecurePasswordEvent.php')
-rw-r--r--lib/public/Security/Events/GenerateSecurePasswordEvent.php34
1 files changed, 32 insertions, 2 deletions
diff --git a/lib/public/Security/Events/GenerateSecurePasswordEvent.php b/lib/public/Security/Events/GenerateSecurePasswordEvent.php
index 8adddd529b0..419e7b40ee4 100644
--- a/lib/public/Security/Events/GenerateSecurePasswordEvent.php
+++ b/lib/public/Security/Events/GenerateSecurePasswordEvent.php
@@ -9,15 +9,34 @@ declare(strict_types=1);
namespace OCP\Security\Events;
use OCP\EventDispatcher\Event;
+use OCP\Security\PasswordContext;
/**
+ * Event to request a secure password to be generated
* @since 18.0.0
*/
class GenerateSecurePasswordEvent extends Event {
- /** @var null|string */
- private $password;
+ private ?string $password;
/**
+ * Request a secure password to be generated.
+ *
+ * By default passwords are generated for the user account context,
+ * this can be adjusted by passing another `PasswordContext`.
+ * @since 31.0.0
+ */
+ public function __construct(
+ private PasswordContext $context = PasswordContext::ACCOUNT,
+ ) {
+ parent::__construct();
+ $this->password = null;
+ }
+
+ /**
+ * Get the generated password.
+ *
+ * If a password generator is registered and successfully generated a password
+ * that password can get read back. Otherwise `null` is returned.
* @since 18.0.0
*/
public function getPassword(): ?string {
@@ -25,9 +44,20 @@ class GenerateSecurePasswordEvent extends Event {
}
/**
+ * Set the generated password.
+ *
+ * This is used by password generators to set the generated password.
* @since 18.0.0
*/
public function setPassword(string $password): void {
$this->password = $password;
}
+
+ /**
+ * Get the context this password should generated for.
+ * @since 31.0.0
+ */
+ public function getContext(): PasswordContext {
+ return $this->context;
+ }
}