Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions lib/private/Setup/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private function createDBUser($connection) {
'exception' => $ex,
'app' => 'mysql.setup',
]);
throw $ex;
}
}

Expand All @@ -137,6 +138,19 @@ private function createDBUser($connection) {
* @param IDBConnection $connection
*/
private function createSpecificUser($username, $connection): void {
$rootUser = $this->dbUser;
$rootPassword = $this->dbPassword;

//create a random password so we don't need to store the admin password in the config file
$saveSymbols = str_replace(['\"', '\\', '\'', '`'], '', ISecureRandom::CHAR_SYMBOLS);
$password = $this->random->generate(22, ISecureRandom::CHAR_ALPHANUMERIC . $saveSymbols)
. $this->random->generate(2, ISecureRandom::CHAR_UPPER)
. $this->random->generate(2, ISecureRandom::CHAR_LOWER)
. $this->random->generate(2, ISecureRandom::CHAR_DIGITS)
. $this->random->generate(2, $saveSymbols)
;
$this->dbPassword = str_shuffle($password);

try {
//user already specified in config
$oldUser = $this->config->getValue('dbuser', false);
Expand All @@ -159,10 +173,6 @@ private function createSpecificUser($username, $connection): void {
if (count($data) === 0) {
//use the admin login data for the new database user
$this->dbUser = $adminUser;

//create a random password so we don't need to store the admin password in the config file
$this->dbPassword = $this->random->generate(30, ISecureRandom::CHAR_ALPHANUMERIC);

$this->createDBUser($connection);

break;
Expand All @@ -179,6 +189,9 @@ private function createSpecificUser($username, $connection): void {
'exception' => $ex,
'app' => 'mysql.setup',
]);
// Restore the original credentials
$this->dbUser = $rootUser;
$this->dbPassword = $rootPassword;
}

$this->config->setValues([
Expand Down