-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforgotpassword.cpp
100 lines (76 loc) · 2.38 KB
/
forgotpassword.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
#include "forgotpassword.h"
#include "ui_forgotpassword.h"
#include<QSqlDatabase>
#include<QSqlQuery>
#include<QMessageBox>
#include"loginpage.h"
forgotPassword::forgotPassword(QWidget *parent) :
QDialog(parent),
ui(new Ui::forgotPassword)
{
ui->setupUi(this);
}
forgotPassword::~forgotPassword()
{
delete ui;
}
void forgotPassword::on_update_PushButton_clicked()
{
QString username = ui->username_lineEdit->text() ;
QString newpw = ui->newPassword_lineEdit->text();
QString checkUser, checkComp;
QSqlDatabase db01 = QSqlDatabase::addDatabase("QSQLITE");
db01.setDatabaseName("C:/Users/PC/OneDrive/Desktop/tryingDB/Companies.db");
if ( db01.open())
{
QSqlQuery qry , qrycomp;
qry.prepare("select * from USER where username=:username");
qry.bindValue(":username" ,username);
if(qry.exec())
{
while(qry.next())
{
checkUser = qry.value(2).toString() ;
}
}
if( checkUser == username)
{
QSqlQuery updatePw ;
updatePw.prepare("UPDATE USER SET password = '"+newpw+"' WHERE username = '"+username+"'");
updatePw.bindValue(":password", newpw);
if( updatePw.exec()){
QMessageBox::information(this,"","Password Successfully Updated"); }
db01.close();
loginpage pp ;
this->close();
pp.exec();
}
qrycomp.prepare("select * from COMPANY where username=:username");
qrycomp.bindValue(":username" ,username);
if(qrycomp.exec())
{
while(qrycomp.next())
{
checkComp = qrycomp.value(4).toString() ;
}
}
if( checkComp == username)
{
QSqlQuery updatePw ;
updatePw.prepare("UPDATE COMPANY SET password = '"+newpw+"' WHERE username = '"+username+"'");
updatePw.bindValue(":password", newpw);
if( updatePw.exec()){
QMessageBox::information(this,"","Password Successfully Updated"); }
db01.close();
loginpage pp ;
this->close();
pp.exec();
}
}
}
void forgotPassword::on_back_clicked()
{
loginpage back ;
hide() ;
back.exec();
}