]>
vaikene.ee Git - evaf/blob - src/apps/PswGen/Generator/module.cpp
2 * @file PswGen/Generator/module.cpp
3 * @brief Implementation of the iGenerator interface
6 * Copyright (c) 2011-2012 Enar Vaikene
8 * This file is part of the eVaf C++ cross-platform application development framework.
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.
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
22 #include <Common/iLogger>
23 #include <Common/iRegistry>
27 VER_EXPORT_VERSION_INFO()
30 using namespace eVaf::PswGen
;
31 using namespace eVaf::PswGen::Generator
;
33 //-------------------------------------------------------------------
38 setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR
).arg(__FUNCTION__
));
40 mGenerator
= new Internal::GeneratorImpl
;
42 EVAF_INFO("%s created", qPrintable(objectName()));
49 EVAF_INFO("%s destroyed", qPrintable(objectName()));
52 bool Module::init(QString
const & args
)
56 EVAF_INFO("%s initialized", qPrintable(objectName()));
63 EVAF_INFO("%s finalized", qPrintable(objectName()));
67 //-------------------------------------------------------------------
69 using namespace eVaf::PswGen::Generator::Internal
;
71 GeneratorImpl::GeneratorImpl()
74 setObjectName(QString("%1.iGenerator").arg(VER_MODULE_NAME_STR
));
76 Common::iRegistry::instance()->registerInterface("iGenerator", this);
78 EVAF_INFO("%s created", qPrintable(objectName()));
81 GeneratorImpl::~GeneratorImpl()
83 EVAF_INFO("%s destroyed", qPrintable(objectName()));
86 QString
GeneratorImpl::generatePassword(QString
const & name
, QString
const & masterPassword
, int length
, uint flags
) const
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();
95 result
.resize(length
);
97 if (flags
& uint(ALPHANUMERIC
)) {
98 // Convert all characters to alpha-numeric
99 for (int i
= 0; i
< result
.size(); ++i
) {
100 unsigned char c
= result
.at(i
);
101 while (isalnum(c
) == 0)