-
Notifications
You must be signed in to change notification settings - Fork 0
/
unlock.cpp
62 lines (48 loc) · 1.38 KB
/
unlock.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "unlock.h"
#include "ui_unlock.h"
#include <QDebug>
#include <QJsonObject>
#include <QJsonDocument>
#include <QFile>
#include <QCryptographicHash>
#include <QProcess>
QJsonObject unlockConfig;
bool unlocked = false;
void Unlock::alarm() {
QProcess* p = new QProcess;
p->start(unlockConfig["command"].toString());
}
void Unlock::quit() {
Unlock::~Unlock();
exit(0);
}
Unlock::Unlock(QWidget *parent) : QWidget(parent), ui(new Ui::Unlock) {
ui->setupUi(this);
QString homeDirectory = getenv("HOME");
QFile file;
QString data;
file.setFileName(homeDirectory + "/.config/fake-gnome-keyring/config.json");
file.open(QIODevice::ReadOnly | QIODevice::Text);
data = file.readAll();
file.close();
unlockConfig = QJsonDocument::fromJson(data.toUtf8()).object();
this->connect(ui->unlockPushButton, &QPushButton::clicked, this,
[this]() {
QString realMD5 = unlockConfig["pwdHash"].toString();
QString userMD5 = QCryptographicHash::hash(ui->pwdLineEdit->text().toLatin1(), QCryptographicHash::Md5).toHex();
if (userMD5 == realMD5) {
unlocked = true;
}
quit();
});
this->connect(ui->cancelPushButton, &QPushButton::clicked, this,
[this]() {
quit();
});
}
Unlock::~Unlock() {
if (!unlocked) {
alarm();
}
delete ui;
}