File tree 7 files changed +533
-0
lines changed
7 files changed +533
-0
lines changed Original file line number Diff line number Diff line change
1
+ QT += core
2
+ QT += network
3
+ QT -= gui
4
+
5
+ CONFIG += c++11
6
+
7
+ TARGET = license-check-console
8
+ CONFIG += console
9
+ CONFIG -= app_bundle
10
+
11
+ TEMPLATE = app
12
+
13
+ SOURCES += main.cpp \
14
+ license.cpp \
15
+ validate.cpp
16
+
17
+ # The following define makes your compiler emit warnings if you use
18
+ # any feature of Qt which as been marked deprecated (the exact warnings
19
+ # depend on your compiler). Please consult the documentation of the
20
+ # deprecated API in order to know how to port your code away from it.
21
+ DEFINES += QT_DEPRECATED_WARNINGS
22
+
23
+ # You can also make your code fail to compile if you use deprecated APIs.
24
+ # In order to do so, uncomment the following line.
25
+ # You can also select to disable deprecated APIs only up to a certain version of Qt.
26
+ # DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
27
+
28
+ HEADERS += \
29
+ license.h \
30
+ validate.h
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change
1
+ #include " license.h"
2
+
3
+ #include < QCryptographicHash>
4
+
5
+ QByteArray License::generateLicenseHash (QByteArray addr)
6
+ {
7
+ return QCryptographicHash::hash (addr, QCryptographicHash::Md4);
8
+ }
9
+
10
+ QDate License::getExpiryDate () const
11
+ {
12
+ return _expiryDate;
13
+ }
14
+
15
+ QByteArray License::getLicenseHash () const
16
+ {
17
+ return _licenseHash;
18
+ }
19
+
20
+ QString License::getMacAddress () const
21
+ {
22
+ return _macAddress;
23
+ }
24
+
25
+ void License::setExpiryDate (QDate expiry)
26
+ {
27
+ _expiryDate = expiry;
28
+ }
29
+
30
+ void License::setMacAddress (QString mac)
31
+ {
32
+ _macAddress = mac;
33
+ }
Original file line number Diff line number Diff line change
1
+ #ifndef LICENSE_H
2
+ #define LICENSE_H
3
+
4
+ #include < QHash>
5
+ #include < QDate>
6
+ // #include <QFile>
7
+ #include < QByteArray>
8
+
9
+ class License
10
+ {
11
+ public:
12
+ // Constructors
13
+ License () :
14
+ _macAddress (" " ), _expiryDate(QDate::currentDate()), _licenseHash(" " ) {}
15
+
16
+ License (QString mac):
17
+ _macAddress (mac), _expiryDate(QDate::currentDate())
18
+ {
19
+ _licenseHash = generateLicenseHash (_macAddress.toLatin1 ());
20
+ }
21
+
22
+ License (QString mac, QDate expiry) :
23
+ _macAddress (mac),
24
+ _expiryDate (expiry)
25
+ {
26
+ _licenseHash = generateLicenseHash (_macAddress.toLatin1 ());
27
+ }
28
+
29
+ // Generate the Hash from a MAC addr
30
+ QByteArray generateLicenseHash (QByteArray addr);
31
+
32
+ // Write the generated license hash and expiry date to a file
33
+ // void saveToFile();
34
+
35
+ // Getter methods
36
+ QDate getExpiryDate () const ;
37
+ QString getMacAddress () const ;
38
+ QByteArray getLicenseHash () const ;
39
+
40
+ // Setter methods
41
+ void setExpiryDate (QDate date);
42
+ void setMacAddress (QString mac);
43
+
44
+ private:
45
+ QDate _expiryDate;
46
+ QString _macAddress;
47
+ QByteArray _licenseHash;
48
+ };
49
+
50
+ #endif // LICENSE_H
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+
3
+ #include < QDebug>
4
+ #include < QCoreApplication>
5
+
6
+ #include " license.h"
7
+ #include " validate.h"
8
+
9
+ int main (int argc, char *argv[])
10
+ {
11
+ QCoreApplication a (argc, argv);
12
+
13
+ std::string macAddr;
14
+ QString _macAddr;
15
+
16
+ std::cout << " Enter MAC address : " ;
17
+ std::cin >> macAddr;
18
+
19
+ _macAddr = QString::fromStdString (macAddr);
20
+
21
+ License *l = new License (_macAddr);
22
+ Validate v (l);
23
+
24
+ v.isValidLicense () ? qDebug () << " Valid License" : qDebug () << " Invalid License" ;
25
+
26
+ return a.exec ();
27
+ }
Original file line number Diff line number Diff line change
1
+ #include " validate.h"
2
+
3
+ #include < QtNetwork/QNetworkInterface>
4
+
5
+ Validate::~Validate ()
6
+ {
7
+ delete m_license;
8
+ }
9
+
10
+ License* Validate::getLicense () const
11
+ {
12
+ return m_license;
13
+ }
14
+
15
+ bool Validate::isValidLicense () const
16
+ {
17
+ const QString interfaceName = " wlo1" ;
18
+ QNetworkInterface interface = QNetworkInterface::interfaceFromName (interfaceName);
19
+
20
+ // qDebug() << "Machine MAC address = " << interface.hardwareAddress();
21
+ // qDebug() << "MAC address provided = " << m_license->getMacAddress().toUpper();
22
+
23
+ return interface.hardwareAddress () == m_license->getMacAddress ().toUpper ();
24
+ }
25
+
26
+ void Validate::setLicense (License *license)
27
+ {
28
+ m_license = license;
29
+ }
Original file line number Diff line number Diff line change
1
+ #ifndef VALIDATE_H
2
+ #define VALIDATE_H
3
+
4
+ #include " license.h"
5
+
6
+ class Validate
7
+ {
8
+ public:
9
+ // Constructor
10
+ Validate (License *ptr) : m_license(ptr)
11
+ {
12
+ }
13
+
14
+ // Destructor
15
+ ~Validate ();
16
+
17
+ // Getter methods
18
+ License* getLicense () const ;
19
+ bool isValidLicense () const ;
20
+
21
+ // Setter methods
22
+ void setLicense (License *license);
23
+
24
+ private:
25
+ License *m_license;
26
+ };
27
+
28
+ #endif // VALIDATE_H
You can’t perform that action at this time.
0 commit comments