mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-12-16 00:44:17 -05:00
CLI: Cleanup create options (#4313)
* Add ability to create database with an empty password * Add password repeat check * Standardize process between `db-create` and `import` commands * Improve db-create tests with new password repeat Co-authored-by: Jonathan White <support@dmapps.us>
This commit is contained in:
parent
b045160e4f
commit
e6c2c7ed93
8 changed files with 171 additions and 54 deletions
|
|
@ -36,12 +36,24 @@ const QCommandLineOption Create::DecryptionTimeOption =
|
|||
QObject::tr("Target decryption time in MS for the database."),
|
||||
QObject::tr("time"));
|
||||
|
||||
const QCommandLineOption Create::SetKeyFileOption =
|
||||
QCommandLineOption(QStringList() << "k"
|
||||
<< "set-key-file",
|
||||
QObject::tr("Set the key file for the database."),
|
||||
QObject::tr("path"));
|
||||
|
||||
const QCommandLineOption Create::SetPasswordOption =
|
||||
QCommandLineOption(QStringList() << "p"
|
||||
<< "set-password",
|
||||
QObject::tr("Set a password for the database."));
|
||||
|
||||
Create::Create()
|
||||
{
|
||||
name = QString("db-create");
|
||||
description = QObject::tr("Create a new database.");
|
||||
positionalArguments.append({QString("database"), QObject::tr("Path of the database."), QString("")});
|
||||
options.append(Command::KeyFileOption);
|
||||
options.append(Create::SetKeyFileOption);
|
||||
options.append(Create::SetPasswordOption);
|
||||
options.append(Create::DecryptionTimeOption);
|
||||
}
|
||||
|
||||
|
|
@ -97,21 +109,26 @@ int Create::execute(const QStringList& arguments)
|
|||
|
||||
auto key = QSharedPointer<CompositeKey>::create();
|
||||
|
||||
auto password = Utils::getPasswordFromStdin();
|
||||
if (!password.isNull()) {
|
||||
key->addKey(password);
|
||||
if (parser->isSet(Create::SetPasswordOption)) {
|
||||
auto passwordKey = Utils::getPasswordFromStdin();
|
||||
if (passwordKey.isNull()) {
|
||||
err << QObject::tr("Failed to set database password.") << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
key->addKey(passwordKey);
|
||||
}
|
||||
|
||||
QSharedPointer<FileKey> fileKey;
|
||||
if (parser->isSet(Command::KeyFileOption)) {
|
||||
if (!loadFileKey(parser->value(Command::KeyFileOption), fileKey)) {
|
||||
if (parser->isSet(Create::SetKeyFileOption)) {
|
||||
QSharedPointer<FileKey> fileKey;
|
||||
|
||||
if (!loadFileKey(parser->value(Create::SetKeyFileOption), fileKey)) {
|
||||
err << QObject::tr("Loading the key file failed") << endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fileKey.isNull()) {
|
||||
key->addKey(fileKey);
|
||||
if (!fileKey.isNull()) {
|
||||
key->addKey(fileKey);
|
||||
}
|
||||
}
|
||||
|
||||
if (key->isEmpty()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue