Skip to content

Commit 33d7a96

Browse files
committed
Create more secure passwords by default
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent d275c93 commit 33d7a96

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/private/Setup/MySQL.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ private function createSpecificUser($username, $connection): void {
141141
$rootUser = $this->dbUser;
142142
$rootPassword = $this->dbPassword;
143143

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+
144154
try {
145155
//user already specified in config
146156
$oldUser = $this->config->getValue('dbuser', false);
@@ -163,10 +173,6 @@ private function createSpecificUser($username, $connection): void {
163173
if (count($data) === 0) {
164174
//use the admin login data for the new database user
165175
$this->dbUser = $adminUser;
166-
167-
//create a random password so we don't need to store the admin password in the config file
168-
$this->dbPassword = $this->random->generate(30, ISecureRandom::CHAR_ALPHANUMERIC);
169-
170176
$this->createDBUser($connection);
171177

172178
break;

0 commit comments

Comments
 (0)