]> vaikene.ee Git - evaf/blob - src/apps/PswGen/Generator/module.cpp
Warning fixes and copyright update.
[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-2019 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
22 #include <Common/iLogger>
23 #include <Common/iRegistry>
24
25 #include <QtCore>
26
27 VER_EXPORT_VERSION_INFO()
28
29 using namespace eVaf;
30 using namespace eVaf::PswGen;
31 using namespace eVaf::PswGen::Generator;
32
33 //-------------------------------------------------------------------
34
35 Module::Module()
36 : Plugins::iPlugin()
37 {
38 setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR).arg(__FUNCTION__));
39
40 mGenerator = new Internal::GeneratorImpl;
41
42 EVAF_INFO("%s created", qPrintable(objectName()));
43 }
44
45 Module::~Module()
46 {
47 delete mGenerator;
48
49 EVAF_INFO("%s destroyed", qPrintable(objectName()));
50 }
51
52 bool Module::init(QString const & args)
53 {
54 Q_UNUSED(args)
55
56 EVAF_INFO("%s initialized", qPrintable(objectName()));
57
58 return true;
59 }
60
61 void Module::done()
62 {
63 EVAF_INFO("%s finalized", qPrintable(objectName()));
64 }
65
66
67 //-------------------------------------------------------------------
68
69 using namespace eVaf::PswGen::Generator::Internal;
70
71 GeneratorImpl::GeneratorImpl()
72 : QObject()
73 {
74 setObjectName(QString("%1.iGenerator").arg(VER_MODULE_NAME_STR));
75
76 Common::iRegistry::instance()->registerInterface("iGenerator", this);
77
78 EVAF_INFO("%s created", qPrintable(objectName()));
79 }
80
81 GeneratorImpl::~GeneratorImpl()
82 {
83 EVAF_INFO("%s destroyed", qPrintable(objectName()));
84 }
85
86 QString GeneratorImpl::generatePassword(QString const & name, QString const & masterPassword, int length, uint flags) const
87 {
88 Q_UNUSED(flags)
89
90 QByteArray inputString = QString("%1%2").arg(name).arg(masterPassword).toLatin1();
91 QCryptographicHash hash(QCryptographicHash::Md5);
92 hash.addData(inputString);
93 QByteArray result = hash.result().toBase64();
94 if (length > 0)
95 result.resize(length);
96
97 if (flags & uint(ALPHANUMERIC)) {
98 // Convert all characters to alpha-numeric
99 for (int i = 0; i < result.size(); ++i) {
100 char c = result.at(i);
101 while (isalnum(c) == 0)
102 c++;
103 result[i] = c;
104 }
105 }
106
107 return result;
108 }