diff --git a/kutils/kpasswdstore/CMakeLists.txt b/kutils/kpasswdstore/CMakeLists.txt index a873e4d8..20b666c8 100644 --- a/kutils/kpasswdstore/CMakeLists.txt +++ b/kutils/kpasswdstore/CMakeLists.txt @@ -12,8 +12,6 @@ add_definitions(-DKDE_DEFAULT_DEBUG_AREA=51004) set(kpasswdstore_LIB_SRCS kpasswdstore.cpp - kpasswdroulettedialog.cpp - kpasswdroulettedialog.ui ) add_library(kpasswdstore SHARED ${kpasswdstore_LIB_SRCS}) @@ -35,7 +33,6 @@ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/kpasswdstore_export.h kpasswdstore.h - kpasswdroulettedialog.h DESTINATION ${KDE4_INCLUDE_INSTALL_DIR} ) diff --git a/kutils/kpasswdstore/kpasswdroulettedialog.cpp b/kutils/kpasswdstore/kpasswdroulettedialog.cpp deleted file mode 100644 index d4606ea1..00000000 --- a/kutils/kpasswdstore/kpasswdroulettedialog.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2022 Ivailo Monev - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2, as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "kpasswdroulettedialog.h" -#include "krandom.h" -#include "klocale.h" -#include "kdebug.h" - -#include "ui_kpasswdroulettedialog.h" - -#include - -class KPasswdRouletteDialogPrivate -{ -public: - KPasswdRouletteDialogPrivate(); - - bool isvalid; - QString validpasswd; - QMap passwdmap; - Ui::KPasswdRouletteDialogUI ui; -}; - -KPasswdRouletteDialogPrivate::KPasswdRouletteDialogPrivate() - : isvalid(false) -{ -} - -KPasswdRouletteDialog::KPasswdRouletteDialog(QWidget *parent) - : KDialog(parent), - d(new KPasswdRouletteDialogPrivate()) -{ - KDialog::setButtons(KDialog::Ok | KDialog::Cancel); - - d->ui.setupUi(mainWidget()); - - d->ui.ksqueezedtextlabel->setText(i18n("Enter password:")); - d->ui.klineedit->setFocus(); -} - -KPasswdRouletteDialog::~KPasswdRouletteDialog() -{ - delete d; -} - -bool KPasswdRouletteDialog::fortunate(const uint max) -{ - QMap passwordsmap; - while (passwordsmap.size() < max) { - QProcess fortuneproc(this); - fortuneproc.start("fortune"); - if (!fortuneproc.waitForStarted() || !fortuneproc.waitForFinished()) { - kWarning() << "Fortune process failed"; - return false; - } - const QByteArray fortunedata = fortuneproc.readAllStandardOutput(); - QString question; - QString answer; - foreach (const QByteArray &fortuneline, fortunedata.split('\n')) { - const QByteArray trimmedfortuneline = fortuneline.trimmed(); - if (trimmedfortuneline.startsWith("Q:")) { - question = QString::fromLocal8Bit(trimmedfortuneline.constData(), trimmedfortuneline.size()); - question = question.mid(2).trimmed(); - } else if (trimmedfortuneline.startsWith("A:")) { - answer = QString::fromLocal8Bit(trimmedfortuneline.constData(), trimmedfortuneline.size()); - answer = answer.mid(2).trimmed(); - } - if (!question.isEmpty() && !answer.isEmpty()) { - passwordsmap.insert(question, answer); - break; - } - } - } - - foreach (const QString &question, passwordsmap.keys()) { - addPasswd(question, passwordsmap.value(question)); - } - return true; -} - -void KPasswdRouletteDialog::addPasswd(const QString &label, const QString &passwd) -{ - d->passwdmap.insert(label, passwd); - - const int randomrange = KRandom::randomMax(d->passwdmap.size()); - const QList labelslist = d->passwdmap.keys(); - const QString randomkey = labelslist.at(randomrange); - d->validpasswd = d->passwdmap.value(randomkey); - - d->ui.ksqueezedtextlabel->setText(randomkey); - d->ui.klineedit->clear(); -} - -bool KPasswdRouletteDialog::isValid() const -{ - return d->isvalid; -} - -void KPasswdRouletteDialog::accept() -{ - d->isvalid = (d->ui.klineedit->text() == d->validpasswd); - KDialog::accept(); -} diff --git a/kutils/kpasswdstore/kpasswdroulettedialog.h b/kutils/kpasswdstore/kpasswdroulettedialog.h deleted file mode 100644 index a31d29e2..00000000 --- a/kutils/kpasswdstore/kpasswdroulettedialog.h +++ /dev/null @@ -1,101 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 2022 Ivailo Monev - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2, as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KPASSWDROULETTEDIALOG_H -#define KPASSWDROULETTEDIALOG_H - -#include "kpasswdstore_export.h" - -#include -#include - -class KPasswdRouletteDialogPrivate; - -/*! - Class to ask for password from a choice of several passwords. The choice is not for the user - to make however, it is up to RNG which of the added choices will to be presented. - - @code - KPasswdRouletteDialog kpasswdroulettedialog; - kpasswdroulettedialog.addPasswd("Is foo in the bar?", "no"); - kpasswdroulettedialog.addPasswd("Can I haz a password?", "yes"); - if (kpasswdroulettedialog.exec() != KPasswdRouletteDialog::Accepted) { - qDebug() << "password dialog not accepted"; - } else if (kpasswdroulettedialog.isValid()) { - qDebug() << "password is valid"; - } else { - qWarning() << "password is not valid"; - } - @endcode - - Alternatively, if you have fortune installed: - @code - KPasswdRouletteDialog kpasswdroulettedialog; - if (kpasswdroulettedialog.fortunate()) { - if (kpasswdroulettedialog.exec() != KPasswdRouletteDialog::Accepted) { - qDebug() << "password dialog not accepted"; - } else if (kpasswdroulettedialog.isValid()) { - qDebug() << "password is valid"; - } else { - qWarning() << "password is not valid"; - } - } else { - qWarning() << "fortune not available"; - } - @endcode - - @since 4.21 -*/ -class KPASSWDSTORE_EXPORT KPasswdRouletteDialog : public KDialog -{ - Q_OBJECT -public: - /*! - @brief Contructs object with @p parent - */ - KPasswdRouletteDialog(QWidget *parent = nullptr); - ~KPasswdRouletteDialog(); - - /*! - @brief Adds answers from `fortune` as valid choices, not more than @p max - @warning This can take a lot of time depending on the available fortunes - and RNG, may never end actually. The answer to pretty much every question - `fortune` can output must also be known - */ - bool fortunate(const uint max = 4); - - /*! - @brief Adds @p passwd as valid choice with the given @p label - */ - void addPasswd(const QString &label, const QString &passwd); - - /*! - @brief Returns @p true if valid password was entered, @p false - otherwise - */ - bool isValid() const; - -public Q_SLOTS: - virtual void accept(); - -private: - Q_DISABLE_COPY(KPasswdRouletteDialog); - KPasswdRouletteDialogPrivate *const d; -}; - -#endif // KPASSWDROULETTEDIALOG_H diff --git a/kutils/kpasswdstore/kpasswdroulettedialog.ui b/kutils/kpasswdstore/kpasswdroulettedialog.ui deleted file mode 100644 index 4b80e90f..00000000 --- a/kutils/kpasswdstore/kpasswdroulettedialog.ui +++ /dev/null @@ -1,68 +0,0 @@ - - - KPasswdRouletteDialogUI - - - - 0 - 0 - 385 - 80 - - - - KPasswdRouletteDialogUI - - - - - - - 0 - 0 - - - - KSqueezedTextLabel - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - QLineEdit::Password - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - KLineEdit - -
klineedit.h
-
- - KSqueezedTextLabel - -
ksqueezedtextlabel.h
-
-
- -