]> vaikene.ee Git - evaf/blob - src/apps/PswGen/Generator/module.cpp
27354f52a630575fa5e9e1ff3f99d3f58b501923
[evaf] / src / apps / PswGen / Generator / module.cpp
1 /**
2 * @file PswGen/Generator/module.cpp
3 * @brief Implementation of the iGenerator interface
4 * @author Enar Vaikene
5 *
6 * Copyright (c) 2011 Enar Vaikene
7 *
8 * This file is part of the eVaf C++ cross-platform application development framework.
9 *
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
15 *
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
18 */
19
20 #include "module.h"
21 #include "version.h"
22
23 #include <Common/iLogger>
24 #include <Common/iRegistry>
25
26 #include <QtCore>
27
28 VER_EXPORT_VERSION_INFO()
29 Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR, eVaf::PswGen::Generator::Module)
30
31 using namespace eVaf;
32 using namespace eVaf::PswGen;
33 using namespace eVaf::PswGen::Generator;
34
35 //-------------------------------------------------------------------
36
37 Module::Module()
38 : Plugins::iPlugin()
39 {
40 setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR).arg(__FUNCTION__));
41
42 mGenerator = new Internal::GeneratorImpl;
43
44 EVAF_INFO("%s created", qPrintable(objectName()));
45 }
46
47 Module::~Module()
48 {
49 delete mGenerator;
50
51 EVAF_INFO("%s destroyed", qPrintable(objectName()));
52 }
53
54 bool Module::init(QString const & args)
55 {
56 Q_UNUSED(args);
57
58 EVAF_INFO("%s initialized", qPrintable(objectName()));
59
60 return true;
61 }
62
63 void Module::done()
64 {
65 EVAF_INFO("%s finalized", qPrintable(objectName()));
66 }
67
68
69 //-------------------------------------------------------------------
70
71 using namespace eVaf::PswGen::Generator::Internal;
72
73 GeneratorImpl::GeneratorImpl()
74 : iGenerator()
75 {
76 setObjectName(QString("%1.iGenerator").arg(VER_MODULE_NAME_STR));
77
78 Common::iRegistry::instance()->registerInterface("iGenerator", this);
79
80 EVAF_INFO("%s created", qPrintable(objectName()));
81 }
82
83 GeneratorImpl::~GeneratorImpl()
84 {
85 EVAF_INFO("%s destroyed", qPrintable(objectName()));
86 }
87
88 QString GeneratorImpl::generatePassword(QString const & name, QString const & masterPassword, int length, uint flags) const
89 {
90 Q_UNUSED(flags);
91
92 QByteArray inputString = QString("%1%2").arg(name).arg(masterPassword).toLatin1();
93 QCryptographicHash hash(QCryptographicHash::Md5);
94 hash.addData(inputString);
95 QByteArray result = hash.result().toBase64();
96 if (length > 0)
97 return result.left(length);
98 else
99 return result;
100 }