Skip to content

Commit 478690b

Browse files
Merge pull request #33513 from nextcloud/bugfix/noid/recover-installation-when-creating-the-user-failed
Recover installation when creating the database user fails and improve password strength
2 parents 7391c81 + 33d7a96 commit 478690b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

lib/private/Setup/MySQL.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ private function createDBUser($connection) {
129129
'exception' => $ex,
130130
'app' => 'mysql.setup',
131131
]);
132+
throw $ex;
132133
}
133134
}
134135

@@ -137,6 +138,19 @@ private function createDBUser($connection) {
137138
* @param IDBConnection $connection
138139
*/
139140
private function createSpecificUser($username, $connection): void {
141+
$rootUser = $this->dbUser;
142+
$rootPassword = $this->dbPassword;
143+
144+
//create a random password so we don't need to store the admin password in the config file
145+
$saveSymbols = str_replace(['\"', '\\', '\'', '`'], '', ISecureRandom::CHAR_SYMBOLS);
146+
$password = $this->random->generate(22, ISecureRandom::CHAR_ALPHANUMERIC . $saveSymbols)
147+
. $this->random->generate(2, ISecureRandom::CHAR_UPPER)
148+
. $this->random->generate(2, ISecureRandom::CHAR_LOWER)
149+
. $this->random->generate(2, ISecureRandom::CHAR_DIGITS)
150+
. $this->random->generate(2, $saveSymbols)
151+
;
152+
$this->dbPassword = str_shuffle($password);
153+
140154
try {
141155
//user already specified in config
142156
$oldUser = $this->config->getValue('dbuser', false);
@@ -159,10 +173,6 @@ private function createSpecificUser($username, $connection): void {
159173
if (count($data) === 0) {
160174
//use the admin login data for the new database user
161175
$this->dbUser = $adminUser;
162-
163-
//create a random password so we don't need to store the admin password in the config file
164-
$this->dbPassword = $this->random->generate(30, ISecureRandom::CHAR_ALPHANUMERIC);
165-
166176
$this->createDBUser($connection);
167177

168178
break;
@@ -179,6 +189,9 @@ private function createSpecificUser($username, $connection): void {
179189
'exception' => $ex,
180190
'app' => 'mysql.setup',
181191
]);
192+
// Restore the original credentials
193+
$this->dbUser = $rootUser;
194+
$this->dbPassword = $rootPassword;
182195
}
183196

184197
$this->config->setValues([

0 commit comments

Comments
 (0)