2019-12-03 13:57:53 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2019-11-19 13:18:00 -05:00
|
|
|
|
|
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2019-11-19 13:18:00 -05:00
|
|
|
*/
|
|
|
|
|
namespace OCP\Security\Events;
|
|
|
|
|
|
|
|
|
|
use OCP\EventDispatcher\Event;
|
2024-08-21 14:23:27 -04:00
|
|
|
use OCP\Security\PasswordContext;
|
2019-11-19 13:18:00 -05:00
|
|
|
|
|
|
|
|
/**
|
2024-08-21 14:23:27 -04:00
|
|
|
* Event to request a secure password to be generated
|
2019-11-19 13:18:00 -05:00
|
|
|
* @since 18.0.0
|
|
|
|
|
*/
|
|
|
|
|
class GenerateSecurePasswordEvent extends Event {
|
2024-08-21 14:23:27 -04:00
|
|
|
private ?string $password;
|
2019-11-19 13:18:00 -05:00
|
|
|
|
|
|
|
|
/**
|
2024-08-21 14:23:27 -04:00
|
|
|
* 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.
|
2019-11-19 13:18:00 -05:00
|
|
|
* @since 18.0.0
|
|
|
|
|
*/
|
|
|
|
|
public function getPassword(): ?string {
|
|
|
|
|
return $this->password;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-08-21 14:23:27 -04:00
|
|
|
* Set the generated password.
|
|
|
|
|
*
|
|
|
|
|
* This is used by password generators to set the generated password.
|
2019-11-19 13:18:00 -05:00
|
|
|
* @since 18.0.0
|
|
|
|
|
*/
|
|
|
|
|
public function setPassword(string $password): void {
|
|
|
|
|
$this->password = $password;
|
|
|
|
|
}
|
2024-08-21 14:23:27 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the context this password should generated for.
|
|
|
|
|
* @since 31.0.0
|
|
|
|
|
*/
|
|
|
|
|
public function getContext(): PasswordContext {
|
|
|
|
|
return $this->context;
|
|
|
|
|
}
|
2019-11-19 13:18:00 -05:00
|
|
|
}
|