Skip to content

Commit f94def1

Browse files
committed
issue#100 Support Nextcloud password_policy
1 parent a2ca6eb commit f94def1

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88
### Added
99
- Users can confirm passwords
10+
- Support Nextcloud password_policy
1011

1112
### Fixed
1213
- Getting user display names backend

lib/Backend/UserBackend.php

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
use OCP\User\Backend\IProvideAvatarBackend;
4646
use OCP\User\Backend\ISetDisplayNameBackend;
4747
use OCP\User\Backend\ISetPasswordBackend;
48+
use Symfony\Component\EventDispatcher\EventDispatcher;
49+
use Symfony\Component\EventDispatcher\GenericEvent;
4850

4951
/**
5052
* The SQL user backend manager.
@@ -89,6 +91,10 @@ final class UserBackend extends ABackend implements
8991
* @var IConfig The config instance.
9092
*/
9193
private $config;
94+
/**
95+
* @var EventDispatcher The event dispatcher.
96+
*/
97+
private $eventDispatcher;
9298
/**
9399
* @var IUserAction[] The actions to execute.
94100
*/
@@ -97,17 +103,19 @@ final class UserBackend extends ABackend implements
97103
/**
98104
* The default constructor.
99105
*
100-
* @param string $AppName The application name.
101-
* @param Cache $cache The cache instance.
102-
* @param ILogger $logger The logger instance.
103-
* @param Properties $properties The properties array.
104-
* @param UserRepository $userRepository The user repository.
105-
* @param IL10N $localization The localization service.
106-
* @param IConfig $config The config instance.
106+
* @param string $AppName The application name.
107+
* @param Cache $cache The cache instance.
108+
* @param ILogger $logger The logger instance.
109+
* @param Properties $properties The properties array.
110+
* @param UserRepository $userRepository The user repository.
111+
* @param IL10N $localization The localization service.
112+
* @param IConfig $config The config instance.
113+
* @param EventDispatcher $eventDispatcher The event dispatcher.
107114
*/
108115
public function __construct(
109116
$AppName, Cache $cache, ILogger $logger, Properties $properties,
110-
UserRepository $userRepository, IL10N $localization, IConfig $config
117+
UserRepository $userRepository, IL10N $localization, IConfig $config,
118+
EventDispatcher $eventDispatcher
111119
) {
112120
$this->appName = $AppName;
113121
$this->cache = $cache;
@@ -116,6 +124,7 @@ public function __construct(
116124
$this->userRepository = $userRepository;
117125
$this->localization = $localization;
118126
$this->config = $config;
127+
$this->eventDispatcher = $eventDispatcher;
119128
$this->actions = [];
120129

121130
$this->initActions();
@@ -492,6 +501,11 @@ public function setPassword(string $uid, string $password): bool
492501
return false;
493502
}
494503

504+
$event = new GenericEvent($password);
505+
$this->eventDispatcher->dispatch(
506+
'OCP\PasswordPolicy::validate', $event
507+
);
508+
495509
$user = $this->userRepository->findByUid($uid);
496510
if (!($user instanceof User)) {
497511
return false;

0 commit comments

Comments
 (0)