-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow_log_in.py
149 lines (133 loc) · 5.32 KB
/
window_log_in.py
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
from pysqlcipher3 import dbapi2 as sqlcipher
from PySide6 import QtSvg, QtXml
from PySide6.QtCore import QRect, Signal
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QMainWindow, QMessageBox, QLineEdit
from ui_log_in import Ui_MainWindow
class LogInWindow(QMainWindow):
logged_in = Signal()
def __init__(self, db):
super(LogInWindow, self).__init__()
self.db = db
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.setFixedWidth(340)
self.setFixedHeight(370)
self.ui.editPassword.setFocus()
with self.db:
try:
self.is_master_pass_created = self.db.execute(
"SELECT name FROM sqlite_master WHERE type='table' AND name='Password';"
).fetchall()
except sqlcipher.DatabaseError:
self.is_master_pass_created = True
if self.is_master_pass_created:
self.setFixedHeight(290)
self.ui.labelHeading.setText("Enter Master Password")
self.ui.labelSubHeading.setText(
"Enter the master password to access your password vault."
)
self.ui.label.deleteLater()
self.ui.groupBox.setFixedHeight(70)
self.ui.groupBoxConfirm.hide()
self.ui.groupBoxConfirm.setGeometry(40, 130, 260, 60)
self.ui.groupBoxConfirm.setTitle("Master password")
self.ui.button.setText("Unlock")
self.ui.button.setGeometry(QRect(40, 225, 260, 27))
# ---- Connecting user actions to the appropriate functions.
self.ui.editPassword.returnPressed.connect(self.log_in)
self.ui.editPasswordConfirm.returnPressed.connect(self.log_in)
self.ui.buttonPasswordToggle1.setCheckable(True)
self.ui.buttonPasswordToggle1.clicked.connect(self.toggle_view1)
self.ui.buttonPasswordToggle2.setCheckable(True)
self.ui.buttonPasswordToggle2.clicked.connect(self.toggle_view2)
self.ui.button.clicked.connect(self.log_in)
# ----------------------------------------------------------
def log_in(self):
if self.is_master_pass_created:
self.check_master_pass_input()
else:
self.create_master_password()
def check_master_pass_input(self):
with self.db:
try:
self.db.execute(f"PRAGMA key='{self.ui.editPassword.text()}';")
self.db.execute("SELECT count(*) FROM sqlite_master;")
self.logged_in.emit()
except sqlcipher.DatabaseError:
QMessageBox.warning(
self,
"Password Manager",
"Incorrect master password. Please try again.",
)
def create_master_password(self):
if (
len(self.ui.editPassword.text()) == 0
or len(self.ui.editPasswordConfirm.text()) == 0
):
QMessageBox.warning(
self,
"Password Manager",
"Confirmation does not match or is empty.",
)
elif self.ui.editPassword.text() != self.ui.editPasswordConfirm.text():
QMessageBox.warning(
self,
"Password Manager",
"Master passwords do not match.",
)
elif (
len(self.ui.editPassword.text()) < 8
and len(self.ui.editPasswordConfirm.text()) < 8
):
QMessageBox.warning(
self,
"Password Manager",
"Your master password must contain at least 8 characters.",
)
else:
with self.db:
self.db.execute(
f"PRAGMA key='{self.ui.editPassword.text()}';",
)
self.db.execute(
"""
CREATE TABLE IF NOT EXISTS Password (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
url TEXT,
username TEXT,
password TEXT,
isCompromised INTEGER,
passwordStrength INTEGER
);
"""
)
QMessageBox.information(
self,
"Password Manager",
"Your master password has been created successfully.",
)
self.logged_in.emit()
def toggle_view1(self, checked):
self.ui.editPassword.setEchoMode(
QLineEdit.EchoMode.Normal
if checked
else QLineEdit.EchoMode.Password
)
self.ui.buttonPasswordToggle1.setIcon(
QIcon("icons/eye.svg")
if checked
else QIcon("icons/eye-crossed.svg")
)
def toggle_view2(self, checked):
self.ui.editPasswordConfirm.setEchoMode(
QLineEdit.EchoMode.Normal
if checked
else QLineEdit.EchoMode.Password
)
self.ui.buttonPasswordToggle2.setIcon(
QIcon("icons/eye.svg")
if checked
else QIcon("icons/eye-crossed.svg")
)