Files
nextcloud-server-mirror/lib/public/Security/Events/GenerateSecurePasswordEvent.php
Daniel Kesselberg 5946964694 docs(ocp): fix event class docblocks
Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Daniel Kesselberg <3902676+kesselb@users.noreply.github.com>
2026-10-29 21:33:00 +00:00

70 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Security\Events;
use OCP\EventDispatcher\Event;
use OCP\Security\PasswordContext;
use SensitiveParameter;
/**
* Event to request a secure password to be generated
* @since 18.0.0
* @since 31.0.0 Provides ``getContext`` to apply different rules per password context, e.g. account or share passwords.
*/
class GenerateSecurePasswordEvent extends Event {
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 {
return $this->password;
}
/**
* Set the generated password.
*
* This is used by password generators to set the generated password.
* @since 18.0.0
*/
public function setPassword(
#[SensitiveParameter]
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;
}
}