using namespace eVaf::PswGen::GUI;
+int const Module::DefaultPasswordLength = 16;
+
Module::Module()
: Plugins::iPlugin()
, mReady(false)
wLength = new QSpinBox;
l->setBuddy(wLength);
wLength->setRange(0, mGenerator->maxLength());
- wLength->setValue(PswGen::iGenerator::DEFAULT_LENGTH);
+ wLength->setValue(DefaultPasswordLength);
wLength->setSpecialValueText(tr("Maximum", VER_MODULE_NAME_STR));
g->addWidget(wLength, 2, 1);
{
if (wMasterPassword->text().isEmpty() || wName->text().isEmpty())
return;
- wPassword->setText(mGenerator->generatePassword(wName->text().toLatin1().constData(), wMasterPassword->text().toLatin1().constData(), wLength->value()));
+ wPassword->setText(mGenerator->generatePassword(wName->text(), wMasterPassword->text(), wLength->value()));
wCopy->setEnabled(true);
}
private: // Members
+ static int const DefaultPasswordLength;
+
/// Flag indicating that the module is ready
bool mReady;
# Source files
set(SRCS
- generator.cpp
+ module.cpp
)
# Header files for the meta-object compiler
set(MOC_HDRS
igenerator.h
- generator.h
+ module.h
)
# Version info resource file for Windows builds
#include "lib.h"
#include <QObject>
+#include <QString>
namespace eVaf {
namespace PswGen {
public:
/// Interface constructor
- iGenerator() {}
+ iGenerator() : QObject() {}
/// Empty virtual destructor
virtual ~iGenerator() {}
ALPHANUMERIC = 0x01 ///< Generated password contains only alphanumeric characters
};
- /**
- * Default length of the generated password
- */
- enum {
- DEFAULT_LENGTH = 16
- };
-
/**
* Generates a strong password
* @param name Name of the password
* @param masterPassword Master password
- * @param length Length of the password
+ * @param length Length of the password (if zero, then uses the max length)
* @param flags Flags for the generator
* @return Generated password
*
*
* Optional flags can be used to fine-tune the generator.
*/
- virtual QString generatePassword(char const * const name, char const * const masterPassword, int length = DEFAULT_LENGTH, uint flags = 0) = 0;
+ virtual QString generatePassword(QString const & name, QString const & masterPassword, int length, uint flags = 0) const = 0;
/**
* Returns the maximum length of generated passwords
/**
- * @file PswGen/Generator/generator.cpp
+ * @file PswGen/Generator/module.cpp
* @brief Implementation of the iGenerator interface
* @author Enar Vaikene
*
* Agreement provided with the Software.
*/
-#include "generator.h"
+#include "module.h"
#include "version.h"
#include <Common/iLogger>
#include <QtCore>
+VER_EXPORT_VERSION_INFO()
+Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR, eVaf::PswGen::Generator::Module)
+
using namespace eVaf;
using namespace eVaf::PswGen;
using namespace eVaf::PswGen::Generator;
Module::Module()
: Plugins::iPlugin()
- , mReady(false)
{
setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR).arg(__FUNCTION__));
EVAF_INFO("%s destroyed", qPrintable(objectName()));
}
-bool Module::init(const QString & args)
+bool Module::init(QString const & args)
{
Q_UNUSED(args);
- if (!mGenerator->init())
- return false;
-
- mReady = true;
-
EVAF_INFO("%s initialized", qPrintable(objectName()));
return true;
void Module::done()
{
- mReady = false;
-
- mGenerator->done();
-
EVAF_INFO("%s finalized", qPrintable(objectName()));
}
EVAF_INFO("%s destroyed", qPrintable(objectName()));
}
-bool GeneratorImpl::init()
-{
- EVAF_INFO("%s initialized", qPrintable(objectName()));
-
- return true;
-}
-
-void GeneratorImpl::done()
+QString GeneratorImpl::generatePassword(QString const & name, QString const & masterPassword, int length, uint flags) const
{
- EVAF_INFO("%s finalized", qPrintable(objectName()));
-}
+ Q_UNUSED(flags);
-QString GeneratorImpl::generatePassword(char const * const name, char const * const masterPassword, int length, uint flags)
-{
QByteArray inputString = QString("%1%2").arg(name).arg(masterPassword).toLatin1();
QCryptographicHash hash(QCryptographicHash::Md5);
hash.addData(inputString);
else
return result;
}
-
-
-//-------------------------------------------------------------------
-
-VER_EXPORT_VERSION_INFO()
-Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR, Module)
/**
- * @file PswGen/Generator/generator.h
+ * @file PswGen/Generator/module.h
* @brief Implementation of the iGenerator interface
* @author Enar Vaikene
*
* Agreement provided with the Software.
*/
-#ifndef __PSWGEN_GENERATOR_GENERATOR_H
-# define __PSWGEN_GENERATOR_GENERATOR_H
+#ifndef __PSWGEN_GENERATOR_MODULE_H
+# define __PSWGEN_GENERATOR_MODULE_H
#include "igenerator.h"
#include <Plugins/iPlugin>
#include <QObject>
+#include <QString>
namespace eVaf {
namespace PswGen {
/// Internal implementation of the Generator module
namespace Internal {
+ class GeneratorImpl;
+} // namespace eVaf::PswGen::Generator::Internal
/**
- * iGenerator interface implementation.
- *
- * Implements the iGenerator interface using MD5 cryptographic hashes.
+ * Module implementing the iGenerator interface.
*/
-
-class GeneratorImpl : public iGenerator
+class Module : public Plugins::iPlugin
{
Q_OBJECT
public:
- GeneratorImpl();
+ Module();
- virtual ~GeneratorImpl();
+ virtual ~Module();
- bool init();
+ virtual bool init(QString const & args);
- void done();
+ virtual void done();
- virtual QString generatePassword(char const * const name, char const * const masterPassword, int length = iGenerator::DEFAULT_LENGTH, uint flags = 0);
+ virtual bool isReady() const { return true; }
- virtual int maxLength() const { return 24; }
+
+private: // Members
+
+ /// iGenerator interface instance
+ Internal::GeneratorImpl * mGenerator;
};
-} // namespace eVaf::PswGen::Generator::Internal
+
+namespace Internal {
/**
- * Module implementing the iGenerator interface.
+ * iGenerator interface implementation.
+ *
+ * Implements the iGenerator interface using MD5 cryptographic hashes.
*/
-class Module : public Plugins::iPlugin
+
+class GeneratorImpl : public iGenerator
{
Q_OBJECT
public:
- Module();
-
- virtual ~Module();
-
- virtual bool init(const QString & args);
-
- virtual void done();
-
- virtual bool isReady() const { return mReady; }
-
+ GeneratorImpl();
-private: // Members
+ virtual ~GeneratorImpl();
- /// Flag indicating that the module is ready
- bool mReady;
+ virtual QString generatePassword(QString const & name, QString const & masterPassword, int length, uint flags = 0) const;
- /// iGenerator interface instance
- Internal::GeneratorImpl * mGenerator;
+ virtual int maxLength() const { return 24; }
};
+} // namespace eVaf::PswGen::Generator::Internal
+
} // namespace eVaf::PswGen::Generator
} // namespace eVaf::PswGen
} // namespace eVaf
-#endif // generator.h
+#endif // module.h