From 791ee382986c6ec9bbff0c89d3f4945e7bd5092e Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 29 Jul 2011 10:15:46 +0200 Subject: [PATCH] SSH: Support password input for private keys in non-GUI applications. Change-Id: Ibd5e47409e92edb6909053d7f17e67b6fa72e642 Reviewed-on: http://codereview.qt.nokia.com/2384 Reviewed-by: Christian Kandeler --- .../utils/ssh/sshkeypasswordretriever.cpp | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/libs/utils/ssh/sshkeypasswordretriever.cpp b/src/libs/utils/ssh/sshkeypasswordretriever.cpp index bcd73aa38b5..938b51feaf3 100644 --- a/src/libs/utils/ssh/sshkeypasswordretriever.cpp +++ b/src/libs/utils/ssh/sshkeypasswordretriever.cpp @@ -31,23 +31,34 @@ **************************************************************************/ #include "sshkeypasswordretriever_p.h" -#include #include +#include #include +#include + namespace Utils { namespace Internal { std::string SshKeyPasswordRetriever::get_passphrase(const std::string &, const std::string &, UI_Result &result) const { - bool ok; - const QString &password = QInputDialog::getText(0, - QCoreApplication::translate("Utils::Ssh", "Password Required"), - QCoreApplication::translate("Utils::Ssh", "Please enter the password for your private key."), - QLineEdit::Password, QString(), &ok); - result = ok ? OK : CANCEL_ACTION; - return std::string(password.toLocal8Bit().data()); + const bool hasGui = dynamic_cast(QApplication::instance()); + if (hasGui) { + bool ok; + const QString &password = QInputDialog::getText(0, + QCoreApplication::translate("Utils::Ssh", "Password Required"), + QCoreApplication::translate("Utils::Ssh", "Please enter the password for your private key."), + QLineEdit::Password, QString(), &ok); + result = ok ? OK : CANCEL_ACTION; + return std::string(password.toLocal8Bit().data()); + } else { + result = OK; + std::string password; + std::cout << "Please enter the password for your private key (set echo off beforehand!): " << std::flush; + std::cin >> password; + return password; + } } } // namespace Internal