-
Notifications
You must be signed in to change notification settings - Fork 0
/
opendatabaseform.cpp
124 lines (115 loc) · 3.28 KB
/
opendatabaseform.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "opendatabaseform.h"
#include "ui_opendatabaseform.h"
#include <QtSql>
#include <QMessageBox>
OpenDatabaseForm::OpenDatabaseForm(QWidget *parent) :
QDialog(parent),
ui(new Ui::OpenDatabaseForm),locked(false),passwordVisible(false)
{
ui->setupUi(this);
QSqlQuery load;
QSqlQueryModel *dbCombo=new QSqlQueryModel();
load.prepare("select dbName from databases");//load all database names to the combobox
load.exec();
dbCombo->setQuery(load);
ui->comboBox_dbNames->setModel(dbCombo);
}
OpenDatabaseForm::~OpenDatabaseForm()
{
delete ui;
main=0;
delete main;
}
void OpenDatabaseForm::setMainFormReference(HomeScreen *mainForm)
{
main=mainForm;
}
void OpenDatabaseForm::setLockFeatures(QString id)
{
locked=true;
ui->label_heading->setText("\t\t Unlock Database");
ui->label_dbName->setHidden(true);
ui->comboBox_dbNames->setHidden(true);
dbID=id;
}
void OpenDatabaseForm::on_pushButton_open_clicked()
{
QString masterKey=ui->lineEdit_masterPass->text();
if(masterKey.isEmpty())
{
QMessageBox::warning(this,tr("Open Database"),tr("Please enter the master password..."));
return;
}
if(locked)//Opening a currently locked database
{
int count;
QSqlQuery open;
open.prepare("select count(*) from databases where dbID='"+dbID+"' and masterKey=HASHBYTES('sha1','"+masterKey+"')");
if(open.exec())
{
while(open.next())
{
count=open.value(0).toInt();
qDebug()<<QString::number(count)<<dbID;
}
if(count==1)//if password is correct
{
main->UnlockWorkspace();
this->close();
}
else
{
QMessageBox::information(this,tr("Lock"),tr("Check password entered..."));
}
}
else
{
qDebug()<<open.lastError().text();
}
}
else//opening a new database
{
main->RemoveRoot();
QSqlQuery open;
QString dbName=ui->comboBox_dbNames->currentText();
open.prepare("select dbID from databases where dbName='"+dbName+"' and masterKey=HASHBYTES('sha1','"+masterKey+"')");
if(open.exec())
{
int count=0;
while(open.next())
{
count++;
dbID=open.value(0).toString();
}
if(count==1)//if correct password entered
{
main->setDatabaseID(dbID);
main->setDatabaseName(dbName);
main->UnlockWorkspace();
this->close();
}
else
{
QMessageBox::warning(this,tr("Open Database"),tr("Check password entered..."));
return;
}
}
else
{
qDebug()<<open.lastError().text();
}
}
}
void OpenDatabaseForm::on_toolButton_passwordVisible_clicked()
{
if(passwordVisible)
{
ui->lineEdit_masterPass->setEchoMode(QLineEdit::EchoMode::Password);
passwordVisible=false;
}
else
{
ui->lineEdit_masterPass->setEchoMode(QLineEdit::EchoMode::Normal);
passwordVisible=true;
}
}