forked from WorldsOfBabylon/ISIS-Messanger
-
Notifications
You must be signed in to change notification settings - Fork 1
/
enterwidget.cpp
76 lines (58 loc) · 2.33 KB
/
enterwidget.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
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "enterwidget.h"
#include<QFileInfo>
#include<QDir>
#include<QCoreApplication>
#include<QDebug>
#include"config.h"
#include <QCryptographicHash>
void enterWidget :: NeedNewAccount(void){
emit NewAccount();
hide();
}
bool enterWidget :: PassCheck(void){
QByteArray passBytes(password->text().toStdString().c_str());
passBytes.append(settings->value("User/Username").toString()); //salt
QByteArray EndedPass = QCryptographicHash::hash(passBytes, QCryptographicHash::Sha1);
if ( EndedPass == settings->value("User/Password") ){
PassOfGuy = (char*)calloc(password->text().toStdString().size()+1,1);
UsernameOfGuy = (char*)calloc(settings->value("User/Username").toString().toStdString().size()+1,1);
strcpy(PassOfGuy, settings->value("User/Username").toString().toStdString().c_str() );
emit PassCorrect();
setVisible(false);
return true;
}
qDebug() << EndedPass << "!=" << settings->value("User/Password").toString();
correctly->show();
correctly->setText(tr("<HTML><b style='color:red'>Not correctly</b></HTML>"));
return false;
}
enterWidget::~enterWidget(){
}
enterWidget::enterWidget(QWidget *parent) : QWidget(parent)
{
this->setFixedSize(500,300);
this->setWindowTitle("Account check");
vbox = new QVBoxLayout (this);
hbox = new QHBoxLayout (this);
password = new QLineEdit (this);
password->setPlaceholderText("your password of account");
okbtn = new QPushButton(this);
newAcc = new QPushButton(this);
correctly = new QLabel(this);
correctly->setText(tr("<HTML><b style='color:brown'>Click and check:)</b></HTML>"));
setLayout(vbox);
vbox->addWidget(password);
vbox->addLayout(hbox);
hbox->addWidget(okbtn);
hbox->addWidget(correctly);
password->setPlaceholderText(tr("password"));
(*password).setEchoMode(QLineEdit::Password);
okbtn->setText("OK");
newAcc->setText(tr("Create new account"));
vbox->addWidget(newAcc);
QFileInfo finfo(QCoreApplication::applicationFilePath());
std::string pathF = finfo.absoluteDir().currentPath().toStdString() + "/" + CONFIG_PATH;
settings = new QSettings((pathF+"/config.ini").c_str(), QSettings::NativeFormat);
connect(okbtn,SIGNAL(clicked(bool)),SLOT(PassCheck()));
connect(newAcc,SIGNAL(clicked(bool)),SLOT(NeedNewAccount()));
}