mirror of https://github.com/MISP/MISP
new: [cli] Add command to trigger password change on next login for users with old pw
parent
828ee92e33
commit
e4deb7914d
|
@ -104,6 +104,14 @@ class UserShell extends AppShell
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
$parser->addSubcommand('require_password_change_for_old_passwords', [
|
||||||
|
'help' => __('Trigger forced password change on next login for users with an old (older than x days) password.'),
|
||||||
|
'parser' => [
|
||||||
|
'arguments' => [
|
||||||
|
'days' => ['help' => __('Amount of days after which a password is considered "old" and needs to be changed.'), 'required' => true]
|
||||||
|
],
|
||||||
|
]
|
||||||
|
]);
|
||||||
return $parser;
|
return $parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,6 +439,35 @@ class UserShell extends AppShell
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function require_password_change_for_old_passwords(){
|
||||||
|
list($days) = $this->args;
|
||||||
|
if(!is_numeric($days)){
|
||||||
|
$this->error("The amount of days after which a password change is required (the argument) should be numeric.");
|
||||||
|
}
|
||||||
|
$interval = 'P' . $days . 'D';
|
||||||
|
|
||||||
|
$current_time = new DateTime();
|
||||||
|
$time_before_change_required = $current_time->sub(new DateInterval($interval))->getTimestamp();
|
||||||
|
$users = $this->User->find('all', [
|
||||||
|
'conditions' => [
|
||||||
|
'OR' => [
|
||||||
|
'last_pw_change <' => $time_before_change_required
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'fields' => ['id'],
|
||||||
|
'recursive' => 0
|
||||||
|
]);
|
||||||
|
foreach ($users as $user) {
|
||||||
|
$user['User']['change_pw'] = true;
|
||||||
|
$userId = $user['User']['id'];
|
||||||
|
if (!$this->User->save($user['User'], true, ["change_pw"])) {
|
||||||
|
$this->out("Could not update user $userId.");
|
||||||
|
$this->out($this->json($this->User->validationErrors));
|
||||||
|
$this->_stop(self::CODE_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|int $userId
|
* @param string|int $userId
|
||||||
* @return array
|
* @return array
|
||||||
|
|
Loading…
Reference in New Issue