diff --git a/lib/Froxlor/Database/Manager/DbManagerMySQL.php b/lib/Froxlor/Database/Manager/DbManagerMySQL.php index e98ea86b..693e229b 100644 --- a/lib/Froxlor/Database/Manager/DbManagerMySQL.php +++ b/lib/Froxlor/Database/Manager/DbManagerMySQL.php @@ -82,9 +82,11 @@ class DbManagerMySQL if (version_compare(Database::getAttribute(\PDO::ATTR_SERVER_VERSION), '8.0.11', '>=')) { // create user $stmt = Database::prepare(" - CREATE USER '" . $username . "'@'" . $access_host . "' IDENTIFIED BY 'password' + CREATE USER '" . $username . "'@'" . $access_host . "' IDENTIFIED BY :password "); - Database::pexecute($stmt); + Database::pexecute($stmt, array( + "password" => $password + )); // grant privileges $stmt = Database::prepare(" GRANT ALL ON `" . $username . "`.* TO :username@:host @@ -96,29 +98,31 @@ class DbManagerMySQL } else { // grant privileges $stmt = Database::prepare(" - GRANT ALL PRIVILEGES ON `" . $username . "`.* TO :username@:host IDENTIFIED BY 'password' + GRANT ALL PRIVILEGES ON `" . $username . "`.* TO :username@:host IDENTIFIED BY :password "); Database::pexecute($stmt, array( "username" => $username, - "host" => $access_host + "host" => $access_host, + "password" => $password )); } - } - // set passoword - if (version_compare(Database::getAttribute(\PDO::ATTR_SERVER_VERSION), '5.7.6', '<')) { - if ($p_encrypted) { - $stmt = Database::prepare("SET PASSWORD FOR :username@:host = :password"); - } else { - $stmt = Database::prepare("SET PASSWORD FOR :username@:host = PASSWORD(:password)"); - } } else { - $stmt = Database::prepare("ALTER USER :username@:host IDENTIFIED BY :password"); + // set passoword + if (version_compare(Database::getAttribute(\PDO::ATTR_SERVER_VERSION), '5.7.6', '<')) { + if ($p_encrypted) { + $stmt = Database::prepare("SET PASSWORD FOR :username@:host = :password"); + } else { + $stmt = Database::prepare("SET PASSWORD FOR :username@:host = PASSWORD(:password)"); + } + } else { + $stmt = Database::prepare("ALTER USER :username@:host IDENTIFIED BY :password"); + } + Database::pexecute($stmt, array( + "username" => $username, + "host" => $access_host, + "password" => $password + )); } - Database::pexecute($stmt, array( - "username" => $username, - "host" => $access_host, - "password" => $password - )); } /** diff --git a/tests/Mysqls/MysqlsTest.php b/tests/Mysqls/MysqlsTest.php index 08117055..b0bd8527 100644 --- a/tests/Mysqls/MysqlsTest.php +++ b/tests/Mysqls/MysqlsTest.php @@ -26,8 +26,9 @@ class MysqlsTest extends TestCase ))->get(); $customer_userdata = json_decode($json_result, true)['data']; + $newPwd = \Froxlor\System\Crypt::generatePassword(); $data = [ - 'mysql_password' => \Froxlor\System\Crypt::generatePassword(), + 'mysql_password' => $newPwd, 'description' => 'testdb', 'sendinfomail' => TRAVIS_CI == 1 ? 0 : 1 ]; @@ -35,6 +36,14 @@ class MysqlsTest extends TestCase $result = json_decode($json_result, true)['data']; $this->assertEquals('testdb', $result['description']); $this->assertEquals(0, $result['dbserver']); + + // test connection + try { + $test_conn = new \PDO("mysql:host=localhost", 'test1sql1', $newPwd); + unset($test_conn); + } catch (PDOException $e) { + $this->fail($e->getMessage()); + } } /**