added database password generation

Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
tracer 2022-01-29 14:38:02 +01:00
parent 2e779ed606
commit c5f2d3044e
1 changed files with 14 additions and 3 deletions

View File

@ -94,15 +94,26 @@ class DatabaseConnection
echo $exception->getMessage() . PHP_EOL;
echo 'Did you create the database and adjust the config file?' . PHP_EOL;
echo PHP_EOL . 'You can create database an user via a panel or manually in mysql shell:' . PHP_EOL;
echo 'CREATE DATABASE databasename;' . PHP_EOL;
echo "CREATE USER 'user'@'localhost' IDENTIFIED BY 'secret';" . PHP_EOL;
echo "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON databasename.* TO 'user'@'localhost';" . PHP_EOL;
$password = $this->generatePassword();
echo 'Created an initial password: ' . $password . PHP_EOL;
echo 'CREATE DATABASE bindAPI;' . PHP_EOL;
echo "CREATE USER 'bindAPI'@'localhost' IDENTIFIED BY '$password';" . PHP_EOL;
echo "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON bindAPI.* TO 'bindAPI'@'localhost';" . PHP_EOL;
echo 'There is no need to run FLUSH PRIVILEGES when using GRANT!' . PHP_EOL;
exit(1);
}
}
function generatePassword($length = 8) {
$chars = '23456789bcdfhkmnprstvzBCDFHJKLMNPRSTVZ';
$shuffled = str_shuffle($chars);
$result = mb_substr($shuffled, 0, $length);
return $result;
}
/**
* @return \PDO
*/