Adding a GUI prompt for password. (#587)

This commit is contained in:
louib 2017-05-22 17:53:41 -04:00 committed by GitHub
parent a75746c7c1
commit c3bd5d21aa
6 changed files with 64 additions and 20 deletions

View file

@ -26,37 +26,47 @@
#include <QStringList>
#include <QTextStream>
#include "gui/UnlockDatabaseDialog.h"
#include "core/Database.h"
#include "core/Entry.h"
#include "core/Group.h"
#include "gui/Clipboard.h"
#include "keys/CompositeKey.h"
int Clip::execute(int argc, char** argv)
{
QApplication app(argc, argv);
QStringList arguments;
for (int i = 0; i < argc; ++i) {
arguments << QString(argv[i]);
}
QTextStream out(stdout);
QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::translate("main", "Copy a password to the clipboard"));
parser.addPositionalArgument("database", QCoreApplication::translate("main", "Path of the database."));
QCommandLineOption guiPrompt(
QStringList() << "g"
<< "gui-prompt",
QCoreApplication::translate("main", "Use a GUI prompt unlocking the database."));
parser.addOption(guiPrompt);
parser.addPositionalArgument("entry", QCoreApplication::translate("main", "Name of the entry to clip."));
parser.process(app);
parser.process(arguments);
const QStringList args = parser.positionalArguments();
if (args.size() != 2) {
QCoreApplication app(argc, argv);
parser.showHelp();
return EXIT_FAILURE;
}
out << "Insert the database password\n> ";
out.flush();
Database* db = nullptr;
QApplication app(argc, argv);
if (parser.isSet("gui-prompt")) {
db = UnlockDatabaseDialog::openDatabasePrompt(args.at(0));
} else {
db = Database::unlockFromStdin(args.at(0));
}
static QTextStream inputTextStream(stdin, QIODevice::ReadOnly);
QString line = inputTextStream.readLine();
CompositeKey key = CompositeKey::readFromLine(line);
Database* db = Database::openDatabaseFile(args.at(0), key);
if (!db) {
return EXIT_FAILURE;
}

View file

@ -47,9 +47,6 @@ int main(int argc, char** argv)
return EXIT_FAILURE;
}
QCoreApplication app(argc, argv);
app.setApplicationVersion(KEEPASSX_VERSION);
QCommandLineParser parser;
QString description("KeePassXC command line interface.");
@ -72,6 +69,8 @@ int main(int argc, char** argv)
// parser.process(app);
if (argc < 2) {
QCoreApplication app(argc, argv);
app.setApplicationVersion(KEEPASSX_VERSION);
parser.showHelp();
return EXIT_FAILURE;
}
@ -104,6 +103,8 @@ int main(int argc, char** argv)
exitCode = Show::execute(argc, argv);
} else {
qCritical("Invalid command %s.", qPrintable(commandName));
QCoreApplication app(argc, argv);
app.setApplicationVersion(KEEPASSX_VERSION);
parser.showHelp();
exitCode = EXIT_FAILURE;
}