Ask for password interactively

This commit is contained in:
Nikolay Degterinsky 2023-02-22 15:58:06 +01:00 committed by GitHub
parent b0427c2e3c
commit cdbff57e6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -327,7 +327,29 @@ try
showClientVersion();
}
connect();
try
{
connect();
}
catch (const Exception & e)
{
if (e.code() == DB::ErrorCodes::AUTHENTICATION_FAILED)
{
if (!config().getString("password", "").empty())
throw;
if (!is_interactive)
throw;
String prompt = fmt::format("Password for user ({}): ", config().getString("user", ""));
String password;
if (auto * result = readpassphrase(prompt, buf, sizeof(buf), 0))
password = result;
config().setString("password", password);
connect();
}
}
/// Show warnings at the beginning of connection.
if (is_interactive && !config().has("no-warnings"))