/** * @file PswGen/Generator/module.cpp * @brief Implementation of the iGenerator interface * @author Enar Vaikene * * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * * This file can be used under the terms of the GNU General Public License * version 3.0 as published by the Free Software Foundation and appearing in * the file LICENSE included in the packaging of this file. Please review the * the following information to ensure the GNU General Public License version * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. * * Alternatively, this file may be used in accordance with the Commercial License * Agreement provided with the Software. */ #include "module.h" #include #include #include VER_EXPORT_VERSION_INFO() using namespace eVaf; using namespace eVaf::PswGen; using namespace eVaf::PswGen::Generator; //------------------------------------------------------------------- Module::Module() : Plugins::iPlugin() { setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR).arg(__FUNCTION__)); mGenerator = new Internal::GeneratorImpl; EVAF_INFO("%s created", qPrintable(objectName())); } Module::~Module() { delete mGenerator; EVAF_INFO("%s destroyed", qPrintable(objectName())); } bool Module::init(QString const & args) { Q_UNUSED(args) EVAF_INFO("%s initialized", qPrintable(objectName())); return true; } void Module::done() { EVAF_INFO("%s finalized", qPrintable(objectName())); } //------------------------------------------------------------------- using namespace eVaf::PswGen::Generator::Internal; GeneratorImpl::GeneratorImpl() : QObject() { setObjectName(QString("%1.iGenerator").arg(VER_MODULE_NAME_STR)); Common::iRegistry::instance()->registerInterface("iGenerator", this); EVAF_INFO("%s created", qPrintable(objectName())); } GeneratorImpl::~GeneratorImpl() { EVAF_INFO("%s destroyed", qPrintable(objectName())); } QString GeneratorImpl::generatePassword(QString const & name, QString const & masterPassword, int length, uint flags) const { Q_UNUSED(flags) QByteArray inputString = QString("%1%2").arg(name).arg(masterPassword).toLatin1(); QCryptographicHash hash(QCryptographicHash::Md5); hash.addData(inputString); QByteArray result = hash.result().toBase64(); if (length > 0) result.resize(length); if (flags & uint(ALPHANUMERIC)) { // Convert all characters to alpha-numeric for (int i = 0; i < result.size(); ++i) { char c = result.at(i); while (isalnum(c) == 0) c++; result[i] = c; } } return result; }