-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpypass_gui.py
114 lines (87 loc) · 3.87 KB
/
pypass_gui.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
from services.user import User
from services.password import Password
import PySimpleGUI as sg
class Pypass:
def __init__(self) -> None:
self.password = ""
self.username = ""
self.isLogged = False
pass
def isUserLogged(self) -> bool:
return self.isLogged
def login(self) -> bool:
connection = User(self.username, self.password)
connection.initDB()
isLogged = connection.login()
return isLogged
def logout(self) -> bool:
isLogged = False
return isLogged
def create_login_window(self):
layout = [
[sg.Text('Username:'), sg.Input(key='-USERNAME-')],
[sg.Text('Password:'), sg.Input(key='-PASSWORD-', password_char='*')],
[sg.Text('Confirm password:'), sg.Input(key='-CPASSWORD-', password_char='*')],
[sg.Button('Login'), sg.Button('Cancel')]
]
window = sg.Window('Login', layout)
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED or event == 'Cancel':
break
if event == 'Login':
self.username = values['-USERNAME-']
self.password = values['-PASSWORD-']
cpassword = values['-CPASSWORD-']
if (self.password != cpassword):
sg.popup('Login failed. Please try again.')
# Add your login logic here
if self.login():
sg.popup('Login successful!')
self.isLogged = True
break
else:
sg.popup('Login failed. Please try again.')
window.close()
def create_select_option(self):
layout = [
[sg.Text('Select Operation:')],
[sg.Combo(['Create', 'GetOne', 'GetAll', 'UpdateOne', 'RemoveOne'], key='-OPERATION-', enable_events=True)],
[sg.Text('Title:'), sg.Input(key='-TITLE-')],
[sg.Text('Email/Username:'), sg.Input(key='-USERNAME-')],
[sg.Text('Password:'), sg.Input(key='-PASSWORD-', password_char='*')],
[sg.Button('Execute'), sg.Button('Cancel')],
]
window = sg.Window('Options', layout)
svcSenha = Password()
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED or event == 'Cancel':
break
if event == 'Execute':
operation = values['-OPERATION-']
title = values['-TITLE-']
username = values['-USERNAME-']
password = values['-PASSWORD-']
if operation == 'Create':
sg.popup(f"Create operation selected. Username: {username}, Password: {password}")
svcSenha.createPassword(title, username, password)
elif operation == 'GetOne':
value = svcSenha.getPassword(title)
sg.popup(f"GetOne operation selected. Title: {value[0]} Username: {value[1]}, Password: {value[2]}")
elif operation == 'GetAll':
values = svcSenha.getAllPasswords()
formatedValues = ""
for value in values:
formatedValues = formatedValues + "Title: {}, Email: {} e Senha: {}".format(value[0], value[1], value[2]) + "\n"
sg.popup(f"{formatedValues}")
elif operation == 'UpdateOne':
pass
elif operation == 'RemoveOne':
svcSenha.deletePassword(title)
sg.popup(f"Password {title} removed")
window.close()
init = Pypass()
init.create_login_window()
if init.isUserLogged() == True:
init.create_select_option()