set password directly when adding new mysql user
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -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,14 +98,15 @@ 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
|
||||
));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// set passoword
|
||||
if (version_compare(Database::getAttribute(\PDO::ATTR_SERVER_VERSION), '5.7.6', '<')) {
|
||||
if ($p_encrypted) {
|
||||
@@ -120,6 +123,7 @@ class DbManagerMySQL
|
||||
"password" => $password
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* removes the given database from the dbms and also
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user