]> vaikene.ee Git - evaf/commitdiff
Implementing 'suffix' and alpha-numeric options in the PswGen GUI and CLI.
authorEnar Vaikene <enar.vaikene@logica.com>
Mon, 4 Jun 2012 07:22:03 +0000 (10:22 +0300)
committerEnar Väikene <enar@vaikene.net>
Tue, 5 Jun 2012 06:26:28 +0000 (09:26 +0300)
src/apps/PswGen/CLI/cli.cpp
src/apps/PswGen/CLI/version.h
src/apps/PswGen/GUI/gui.cpp
src/apps/PswGen/GUI/gui.h
src/apps/PswGen/GUI/version.h

index cd18b852b7f096660a5ac1ecf6130b12242d4f11..51ea2b6690351cafa0dc2f654156a856fd2a03b8 100644 (file)
@@ -3,7 +3,7 @@
  * @brief Command line interface for the PswGen application
  * @author Enar Vaikene
  *
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2012 Enar Vaikene
  *
  * This file is part of the eVaf C++ cross-platform application development framework.
  *
@@ -29,6 +29,7 @@
 #include <Common/iEventQueue>
 #include <Common/iApp>
 #include <Common/Event>
+#include <Common/Util>
 
 #include <QtCore>
 
@@ -159,7 +160,10 @@ void Module::generatePassword()
 {
     QString masterPassword;
     QString appName;
+    QString suffix;
     int passwordLength = 0;
+    uint flags = 0;
+    int alnum = -1;
 
     // Process command-line arguments
     QStringList args = QCoreApplication::arguments();
@@ -170,6 +174,18 @@ void Module::generatePassword()
             masterPassword = arg.at(1);
         else if (QRegExp("-[-]?n(ame)?").exactMatch(arg.at(0)) && arg.size() > 1)
             appName = arg.at(1);
+        else if (QRegExp("-[-]?s(uffix)?").exactMatch(arg.at(0)) && arg.size() > 1)
+            suffix = arg.at(1);
+        else if (QRegExp("-[-]?a(lphanumeric)?").exactMatch(arg.at(0))) {
+            if (arg.size() > 1) {
+                if (Common::isTrue(arg.at(1)))
+                    alnum = 1;
+                else if (Common::isFalse(arg.at(1)))
+                    alnum = 0;
+            }
+            else
+                alnum = 1;
+        }
         else if (QRegExp("-[-]?l(ength)?").exactMatch(arg.at(0)) && arg.size() > 1) {
             bool ok;
             int t = arg.at(1).toInt(&ok);
@@ -181,6 +197,14 @@ void Module::generatePassword()
         }
     }
 
+    // Set flags
+    if (alnum != -1) {
+        if (alnum == 1)
+            flags |= uint(iGenerator::ALPHANUMERIC);
+        else
+            flags &= ~uint(iGenerator::ALPHANUMERIC);
+    }
+
     QTextStream cin(stdin);
     QTextStream cout(stdout);
 
@@ -199,8 +223,14 @@ void Module::generatePassword()
     QExplicitlySharedDataPointer<PswGen::Storage::Data> data;
     if (mStorage) {
         data = mStorage->query(appName);
-        if (data && passwordLength == 0)
-            passwordLength = data->length();
+        if (data) {
+            if (passwordLength == 0)
+                passwordLength = data->length();
+            if (suffix.isEmpty())
+                suffix = data->suffix();
+            if (alnum == -1)
+                flags = data->flags();
+        }
     }
 
     // If the length argument is still not initialized, use the default length value
@@ -208,15 +238,17 @@ void Module::generatePassword()
         passwordLength = DefaultPasswordLength;
 
     // Generate password
-    QString password = mGenerator->generatePassword(appName, masterPassword, passwordLength);
+    QString password = mGenerator->generatePassword(appName + suffix, masterPassword, passwordLength);
     cout << "Generated password : " << password << endl;
 
     // Store arguments for this password
     if (mStorage) {
         if (!data)
-            data = new Storage::Data(appName, passwordLength);
-        else
+            data = new Storage::Data(appName, suffix, passwordLength);
+        else {
+            data->setSuffix(suffix);
             data->setLength(passwordLength);
+        }
         mStorage->save(appName, data);
     }
 }
index 348e78a6b48b81057eeb9938c01edfd49432f0f8..eb872f513921e7c71eeaab3914090057dc81b624 100644 (file)
@@ -3,7 +3,7 @@
  * @brief Version information for eVaf modules
  * @author Enar Vaikene
  *
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2012 Enar Vaikene
  *
  * This file is part of the eVaf C++ cross-platform application development framework.
  *
 /**
  * Module/library version number in the form major,minor,release,build
  */
-#define VER_FILE_VERSION                0,1,1,2
+#define VER_FILE_VERSION                0,2,1,3
 
 /**
  * Module/library version number in the string format (shall end with \0)
  */
-#define VER_FILE_VERSION_STR            "0.1.1.2\0"
+#define VER_FILE_VERSION_STR            "0.2.1.3\0"
 
 /**
  * Module/library name (shall end with \0)
index 1ced109fa27cb869ec691d7568d3c0378dd8cb79..9ab2645b9bb745b5aa61ab95bbb0a5a8beecb64c 100644 (file)
@@ -3,7 +3,7 @@
  * @brief GUI for the PswGen application
  * @author Enar Vaikene
  *
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2012 Enar Vaikene
  *
  * This file is part of the eVaf C++ cross-platform application development framework.
  *
@@ -111,24 +111,35 @@ bool Module::init(QString const & args)
     g->addWidget(wName, 1, 1, 1, 2);
     panel->setFocusProxy(wName);
 
-    l = new QLabel(tr("&Length of the password:", VER_MODULE_NAME_STR));
+    l = new QLabel(tr("&Suffix:", VER_MODULE_NAME_STR));
     l->setAlignment(Qt::AlignRight);
     g->addWidget(l, 2, 0);
 
+    wSuffix = new QLineEdit;
+    l->setBuddy(wSuffix);
+    g->addWidget(wSuffix, 2, 1, 1, 2);
+
+    l = new QLabel(tr("&Length of the password:", VER_MODULE_NAME_STR));
+    l->setAlignment(Qt::AlignRight);
+    g->addWidget(l, 3, 0);
+
     wLength = new QSpinBox;
     l->setBuddy(wLength);
     wLength->setRange(0, mGenerator->maxLength());
     wLength->setValue(DefaultPasswordLength);
     wLength->setSpecialValueText(tr("Maximum", VER_MODULE_NAME_STR));
-    g->addWidget(wLength, 2, 1);
+    g->addWidget(wLength, 3, 1);
+
+    wAlNum = new QCheckBox(tr("&Alpha-Numeric only", VER_MODULE_NAME_STR));
+    g->addWidget(wAlNum, 3, 2);
 
     l = new QLabel(tr("Password:"));
     l->setAlignment(Qt::AlignRight);
-    g->addWidget(l, 3, 0);
+    g->addWidget(l, 4, 0);
 
     wPassword = new QLineEdit;
     wPassword->setReadOnly(true);
-    g->addWidget(wPassword, 3, 1, 1, 2);
+    g->addWidget(wPassword, 4, 1, 1, 2);
 
     v->addStretch();
 
@@ -176,8 +187,11 @@ void Module::textChanged(QString const &)
     wGenerate->setDisabled(wMasterPassword->text().isEmpty() || wName->text().isEmpty());
     if (!wName->text().isEmpty() && mStorage) {
         QExplicitlySharedDataPointer<PswGen::Storage::Data> data = mStorage->query(wName->text());
-        if (data)
+        if (data) {
             wLength->setValue(data->length());
+            wSuffix->setText(data->suffix());
+            wAlNum->setChecked(data->flags() & uint(iGenerator::ALPHANUMERIC));
+        }
     }
 }
 
@@ -185,14 +199,27 @@ void Module::generateClicked()
 {
     if (wMasterPassword->text().isEmpty() || wName->text().isEmpty())
         return;
-    wPassword->setText(mGenerator->generatePassword(wName->text(), wMasterPassword->text(), wLength->value()));
+    uint flags = 0;
+    if (wAlNum->isChecked())
+        flags |= iGenerator::ALPHANUMERIC;
+    wPassword->setText(mGenerator->generatePassword(wName->text() + wSuffix->text(),
+                                                    wMasterPassword->text(),
+                                                    wLength->value(),
+                                                    flags));
     wCopy->setEnabled(true);
     if (mStorage) {
         QExplicitlySharedDataPointer<PswGen::Storage::Data> data = mStorage->query(wName->text());
-        if (!data)
-            data = new Storage::Data(wName->text(), wLength->value());
-        else
+        if (!data) {
+            data = new Storage::Data(wName->text(), wSuffix->text(), wLength->value());
+        }
+        else {
+            data->setSuffix(wSuffix->text());
             data->setLength(wLength->value());
+            if (wAlNum->isChecked())
+                data->setFlags(data->flags() | iGenerator::ALPHANUMERIC);
+            else
+                data->setFlags(data->flags() & ~uint(iGenerator::ALPHANUMERIC));
+        }
         mStorage->save(wName->text(), data);
     }
 }
index d3c89d4abf0e54d0c7b609b3bf9f3b97fadd4b27..246b556ac6c37a038920ef8e5052ce6f70e00c1b 100644 (file)
@@ -3,7 +3,7 @@
  * @brief GUI for the PswGen application
  * @author Enar Vaikene
  *
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2012 Enar Vaikene
  *
  * This file is part of the eVaf C++ cross-platform application development framework.
  *
@@ -28,6 +28,7 @@
 class QLineEdit;
 class QSpinBox;
 class QPushButton;
+class QCheckBox;
 
 namespace eVaf {
 namespace PswGen {
@@ -84,9 +85,11 @@ private: // Members
     eVaf::PswGen::iStorage * mStorage;
 
     /// Widgets on the screen
-    QLineEdit * wName;
     QLineEdit * wMasterPassword;
+    QLineEdit * wName;
+    QLineEdit * wSuffix;
     QSpinBox * wLength;
+    QCheckBox * wAlNum;
     QLineEdit * wPassword;
     QPushButton * wGenerate;
     QPushButton * wCopy;
index 8f3e970ab521a83ceaf022a92755ab5f1f58dda7..b9003fd0fcf5943921eb2389caf93e66fa598466 100644 (file)
@@ -3,7 +3,7 @@
  * @brief Version information for eVaf modules
  * @author Enar Vaikene
  *
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2012 Enar Vaikene
  *
  * This file is part of the eVaf C++ cross-platform application development framework.
  *
 /**
  * Module/library version number in the form major,minor,release,build
  */
-#define VER_FILE_VERSION                0,1,5,6
+#define VER_FILE_VERSION                0,2,1,7
 
 /**
  * Module/library version number in the string format (shall end with \0)
  */
-#define VER_FILE_VERSION_STR            "0.1.5.6\0"
+#define VER_FILE_VERSION_STR            "0.2.1.7\0"
 
 /**
  * Module/library name (shall end with \0)