Commit 2fe41a5 1 parent 871b76f commit 2fe41a5 Copy full SHA for 2fe41a5
File tree 2 files changed +16
-4
lines changed
2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -53,16 +53,24 @@ protected function run($argument) {
53
53
$ qb = $ this ->connection ->getQueryBuilder ();
54
54
55
55
// QUESTION: DOES THE DATETIME COMPARAISON WORK WELL WHEN TIMEZONES ENTER THE GAME?
56
+ // I THINK SO, BECAUSE EVERYTHING HAPPENS ON THE SERVER, HENCE ON THE SAME TZ
56
57
$ qb ->select ('id ' )
57
58
->from ('share ' )
58
59
->where ($ qb ->expr ()->lte ('password_expiration_time ' , $ qb ->createNamedParameter ((new \DateTime ())->format ('Y-m-d H:i:s ' ))));
59
60
60
61
$ result = $ qb ->execute ();
61
62
while ($ row = $ result ->fetch ()) {
62
- // QUESTION: SHALL I RESPECT PASSWORD POLICY HERE (WHEN USED)?
63
+
64
+ // Generates a random password respecting any password policy defined
65
+ $ eventDispatcher = \OC ::$ server ->query (IEventDispatcher::class);
66
+ $ event = new \OCP \Security \Events \GenerateSecurePasswordEvent ();
67
+ $ eventDispatcher ->dispatchTyped ($ event );
68
+ $ password = $ event ->getPassword () ?? $ this ->hasher ->hash ($ this ->secureRandom ->generate (20 ));
69
+
70
+ // Updates share password and expiration time
63
71
$ qb ->update ('share ' )
64
72
->where ($ qb ->expr ()->eq ('id ' , $ qb ->createNamedParameter ($ row ['id ' ])))
65
- ->set ('password ' , $ qb ->createNamedParameter ($ this -> hasher -> hash ( $ this -> secureRandom -> generate ( 20 )) ))
73
+ ->set ('password ' , $ qb ->createNamedParameter ($ password ))
66
74
->set ('password_expiration_time ' , $ qb ->createNamedParameter ((new \DateTime ())->add (new \DateInterval ('P1D ' ))->format ('Y-m-d H:i:s ' )))
67
75
->execute ();
68
76
}
Original file line number Diff line number Diff line change @@ -233,8 +233,12 @@ protected function validateIdentity(string $identityToken): bool {
233
233
}
234
234
235
235
protected function generatePassword () {
236
- // QUESTION: SHALL I RESPECT PASSWORD POLICY HERE (WHEN USED)?
237
- $ password = \OC ::$ server ->getSecureRandom ()->generate (20 );
236
+ // Generates a password respecting any password policy defined
237
+ $ eventDispatcher = \OC ::$ server ->query (IEventDispatcher::class);
238
+ $ event = new \OCP \Security \Events \GenerateSecurePasswordEvent ();
239
+ $ eventDispatcher ->dispatchTyped ($ event );
240
+ $ password = $ event ->getPassword () ?? $ password = \OC ::$ server ->getSecureRandom ()->generate (20 );
241
+
238
242
$ this ->share ->setPassword ($ password );
239
243
$ this ->shareManager ->updateShare ($ this ->share , true );
240
244
return ;
You can’t perform that action at this time.
0 commit comments