-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassGuard.py
More file actions
1888 lines (1715 loc) Β· 82.7 KB
/
Copy pathPassGuard.py
File metadata and controls
1888 lines (1715 loc) Β· 82.7 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import sys
from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
QPushButton, QLineEdit, QLabel, QFrame, QListWidget, QListWidgetItem, QComboBox)
from PyQt6.QtCore import Qt, QEvent, QMargins, QUrl, QTimer
from PyQt6.QtGui import QPalette, QColor, QFont, QClipboard, QDesktopServices
from firebase_admin import credentials, firestore, initialize_app
import os
from Crypto.Cipher import AES, PKCS1_OAEP
from Crypto.Protocol.KDF import scrypt
from Crypto.PublicKey import RSA
from Crypto.Random import get_random_bytes
import base64
import random
import string
import re
import cv2
import face_recognition
import psutil
import uuid
import numpy as np
from PyQt6.QtGui import QPixmap
from PyQt6.QtCore import QPropertyAnimation, QEasingCurve
def get_base_path():
if getattr(sys, 'frozen', False):
# If running as a PyInstaller bundle
return sys._MEIPASS
else:
# If running as a normal Python script
return os.path.dirname(os.path.abspath(__file__))
# Initialize Firebase
base_path = get_base_path()
json_path = os.path.join(base_path, "password_manager.json")
cred = credentials.Certificate(json_path)
initialize_app(cred)
db = firestore.client()
users_ref = db.collection("users")
credentials_ref = db.collection("credentials")
def encrypt_with_rsa(data, public_key):
"""Encrypt data with RSA public key using PKCS1_OAEP."""
if isinstance(data, str):
data = data.encode()
rsa_key = RSA.import_key(public_key)
cipher = PKCS1_OAEP.new(rsa_key)
encrypted = cipher.encrypt(data)
return base64.b64encode(encrypted).decode()
def decrypt_with_rsa(encrypted_data, private_key):
"""Decrypt data with RSA private key using PKCS1_OAEP."""
try:
data = base64.b64decode(encrypted_data)
rsa_key = RSA.import_key(private_key)
cipher = PKCS1_OAEP.new(rsa_key)
decrypted = cipher.decrypt(data)
return decrypted
except Exception as e:
print(f"RSA decryption failed: {str(e)}")
return None
# Encryption/Decryption Functions
def encrypt_with_key(data, key):
salt = get_random_bytes(16)
derived_key = scrypt(key.encode() if isinstance(key, str) else key, salt, 32, N=2 ** 14, r=8, p=1)
cipher = AES.new(derived_key, AES.MODE_GCM)
ciphertext, tag = cipher.encrypt_and_digest(data)
return base64.b64encode(salt + cipher.nonce + tag + ciphertext).decode()
def decrypt_with_key(encrypted_data, key):
try:
data = base64.b64decode(encrypted_data)
salt, iv, tag, ciphertext = data[:16], data[16:32], data[32:48], data[48:]
derived_key = scrypt(key.encode() if isinstance(key, str) else key, salt, 32, N=2 ** 14, r=8, p=1)
cipher = AES.new(derived_key, AES.MODE_GCM, nonce=iv)
return cipher.decrypt_and_verify(ciphertext, tag)
except ValueError as e:
print(f"Decryption failed: {e}")
return None
def encrypt_password(password, master_password, public_key):
salt = get_random_bytes(16)
key = scrypt(master_password.encode(), salt, 32, N=2 ** 14, r=8, p=1)
cipher = AES.new(key, AES.MODE_GCM)
encrypted_password, tag = cipher.encrypt_and_digest(password.encode())
rsa_cipher = PKCS1_OAEP.new(RSA.import_key(public_key))
encrypted_key = rsa_cipher.encrypt(key)
return {
"salt": base64.b64encode(salt).decode(),
"nonce": base64.b64encode(cipher.nonce).decode(),
"tag": base64.b64encode(tag).decode(),
"encrypted_password": base64.b64encode(encrypted_password).decode(),
"encrypted_key": base64.b64encode(encrypted_key).decode()
}
def decrypt_password(encrypted_data, master_password, private_key):
salt = base64.b64decode(encrypted_data["salt"])
nonce = base64.b64decode(encrypted_data["nonce"])
tag = base64.b64decode(encrypted_data["tag"])
encrypted_password = base64.b64decode(encrypted_data["encrypted_password"])
encrypted_key = base64.b64decode(encrypted_data["encrypted_key"])
rsa_cipher = PKCS1_OAEP.new(RSA.import_key(private_key))
key = rsa_cipher.decrypt(encrypted_key)
cipher = AES.new(key, AES.MODE_GCM, nonce=nonce)
return cipher.decrypt_and_verify(encrypted_password, tag).decode()
def generate_and_store_keys(user_id, master_password, face_encoding=None, device_id=None, trusted_contact_id=None):
key = RSA.generate(1024) # Use 4096 in production
private_key = key.export_key()
public_key = key.publickey().export_key()
encrypted_private_key = encrypt_with_key(private_key, master_password)
user_data = {
"public_key": public_key.decode(),
"encrypted_private_key": encrypted_private_key
}
if face_encoding is not None:
face_bytes = face_encoding.tobytes()
face_key = base64.b64encode(face_bytes).decode()
user_data["face_recovery_key"] = encrypt_with_key(private_key, face_key)
user_data["face_encoding"] = base64.b64encode(face_bytes).decode()
if device_id is not None:
user_data["device_recovery_key"] = encrypt_with_key(private_key, device_id)
if trusted_contact_id:
contact_doc = users_ref.document(trusted_contact_id).get()
if contact_doc.exists:
contact_public_key = contact_doc.to_dict()["public_key"]
recovery_key = get_random_bytes(32) # 32-byte recovery key
user_data["contact_recovery_key"] = encrypt_with_key(private_key, recovery_key)
# Use RSA to encrypt recovery key for trusted contact
encrypted_recovery_key = encrypt_with_rsa(recovery_key, contact_public_key)
print(
f"Encrypting recovery key for {user_id} with {trusted_contact_id}'s public key: {contact_public_key[:20]}...")
print(f"Storing encrypted key: {encrypted_recovery_key[:20]}... for {user_id} under {trusted_contact_id}")
users_ref.document(trusted_contact_id).update({
f"recovery_keys.{user_id}": encrypted_recovery_key
})
user_data["trusted_contact_id"] = trusted_contact_id
else:
print(f"Trusted contact {trusted_contact_id} not found.")
users_ref.document(user_id).set(user_data)
return public_key, private_key
# Password Generator and Strength Checker
def generate_password(length=16):
characters = string.ascii_letters + string.digits + string.punctuation
return ''.join(random.choice(characters) for _ in range(length))
def check_password_strength(password):
length = len(password)
has_upper = bool(re.search(r'[A-Z]', password))
has_lower = bool(re.search(r'[a-z]', password))
has_digit = bool(re.search(r'\d', password))
has_special = bool(re.search(r'[!@#$%^&*(),.?":{}|<>]', password))
score = 0
if length >= 8: score += 1
if length >= 12: score += 1
if has_upper: score += 1
if has_lower: score += 1
if has_digit: score += 1
if has_special: score += 1
if score <= 2:
return "Weak", "#FF6B6B"
elif score <= 4:
return "Medium", "#FFD166"
else:
return "Strong", "#10B981"
# Main Window
class PasswordManagerWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("PassGuard")
self.setGeometry(100, 100, 1000, 700)
self.is_dark_mode = False
# Central widget and main layout
central_widget = QWidget(self)
self.setCentralWidget(central_widget)
self.main_layout = QHBoxLayout(central_widget) # Changed to self.main_layout for consistency
self.main_layout.setContentsMargins(0, 0, 0, 0)
# Sidebar
self.sidebar = QFrame()
self.sidebar.setFixedWidth(250)
sidebar_layout = QVBoxLayout(self.sidebar)
sidebar_layout.setContentsMargins(15, 30, 15, 30)
logo = QLabel("π PassGuard")
logo.setFont(QFont("Montserrat", 22, QFont.Weight.Bold))
logo.setStyleSheet("color: white;")
sidebar_layout.addWidget(logo, alignment=Qt.AlignmentFlag.AlignCenter)
self.sidebar_buttons = {}
for text, cmd in [("Add Credential", self.show_add_credential),
("View Credentials", self.show_view_credentials),
("Settings", self.show_settings)]:
btn = QPushButton(text)
btn.setFont(QFont("Montserrat", 14))
btn.setStyleSheet("""
QPushButton {
background: transparent;
color: white;
padding: 12px;
border-radius: 8px;
text-align: left;
}
QPushButton:hover { background: rgba(255, 255, 255, 0.2); }
QPushButton:disabled { color: #A0A0A0; }
""")
btn.clicked.connect(lambda checked, c=cmd: self.check_login_before_action(c))
btn.setEnabled(False)
self.sidebar_buttons[text] = btn
sidebar_layout.addWidget(btn)
sidebar_layout.addStretch()
# Content area
self.content = QFrame()
self.content_layout = QVBoxLayout(self.content)
self.content_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
self.content_layout.setContentsMargins(20, 20, 20, 20)
self.password_labels = {}
# Add widgets to main layout
self.main_layout.addWidget(self.sidebar)
self.main_layout.addWidget(self.content, stretch=1)
# Auto-Logout Timer
self.inactivity_timer = QTimer(self)
self.inactivity_timer.timeout.connect(self.logout)
self.inactivity_timer.setInterval(300000) # 5 minutes
# Add floating developer bubble
self.dev_bubble = QPushButton("π¨βπ»", self)
self.dev_bubble.setFixedSize(50, 50)
self.dev_bubble.setStyleSheet("""
QPushButton {
background: #10B981;
color: white;
border-radius: 25px;
border: none;
font-size: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
QPushButton:hover {
background: #059669;
}
""")
self.dev_bubble.move(self.width() - 70, self.height() - 70)
self.dev_bubble.clicked.connect(self.show_dev_info)
self.dev_bubble.setToolTip("Contact Developers")
# Ensure bubble stays in position when window resizes
self.resizeEvent = self.update_bubble_position
# Initialize UI
self.apply_theme()
self.showFullScreen()
self.installEventFilter(self)
self.show_login()
def apply_theme(self):
if self.is_dark_mode:
self.setStyleSheet("background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #2D2D2D, stop:1 #1A1A1A);")
self.content.setStyleSheet("background: rgba(50, 50, 50, 0.95); border-radius: 12px;")
self.sidebar.setStyleSheet("background: #fc6a03; border-radius: 10px;")
else:
self.setStyleSheet("background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #E0E7FF, stop:1 #FFFFFF);")
self.content.setStyleSheet("background: rgba(255, 255, 255, 0.95); border-radius: 12px;")
self.sidebar.setStyleSheet("background: #4A90E2; border-radius: 10px;")
def toggle_theme(self):
self.is_dark_mode = not self.is_dark_mode
self.apply_theme()
self.show_settings()
def update_bubble_position(self, event):
self.dev_bubble.move(self.width() - 70, self.height() - 70)
super().resizeEvent(event)
def show_dev_info(self):
self.clear_content()
# Title with gradient flair
title = QLabel("Help & Support")
title.setFont(QFont("Montserrat", 50, QFont.Weight.Bold))
title.setStyleSheet(f"""
color: {'#4A90E2' if not self.is_dark_mode else '#fc6a03'};
padding: 5px 15px;
""")
self.content_layout.addWidget(title, alignment=Qt.AlignmentFlag.AlignCenter)
# Container for everything
help_container = QWidget()
help_layout = QVBoxLayout(help_container)
help_layout.setSpacing(20)
# Developers Section
dev_section = QFrame()
dev_section.setStyleSheet(f"""
background: {'#F9FAFB' if not self.is_dark_mode else '#313131'};
border-radius: 10px;
padding: 15px;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
""")
dev_layout = QVBoxLayout(dev_section)
dev_layout.setSpacing(15)
dev_title = QLabel("MEET THINKTECH")
dev_title.setFont(QFont("Montserrat", 18, QFont.Weight.Bold))
dev_title.setStyleSheet(f"color: {'#333' if not self.is_dark_mode else '#E0E7FF'};")
dev_layout.addWidget(dev_title, alignment=Qt.AlignmentFlag.AlignCenter)
# ThinkTech Intro
thinktech_intro = QLabel(
"From vision to virtual, from dream to designβThinkTech is the future, in every line.\n"
"We donβt just thinkβwe think tech."
)
thinktech_intro.setFont(QFont("Open Sans", 12, QFont.Weight.Medium))
thinktech_intro.setStyleSheet(f"color: {'#555' if not self.is_dark_mode else '#B0B0B0'}; padding: 5px;")
thinktech_intro.setAlignment(Qt.AlignmentFlag.AlignCenter)
dev_layout.addWidget(thinktech_intro)
# Developer 1
dev1_frame = QFrame()
dev1_layout = QHBoxLayout(dev1_frame)
dev1_icon = QLabel("π¨βπ»")
dev1_icon.setFont(QFont("Open Sans", 30))
dev1_icon.setStyleSheet(f"color: {'#4A90E2' if not self.is_dark_mode else '#fc6a03'};")
dev1_layout.addWidget(dev1_icon)
dev1_info = QLabel("Apoorv Gupta")
dev1_info.setFont(QFont("Open Sans", 16, QFont.Weight.Medium))
dev1_info.setStyleSheet(f"color: {'#333' if not self.is_dark_mode else '#E0E7FF'};")
dev1_layout.addWidget(dev1_info)
dev1_btn = QPushButton("π LinkedIn")
dev1_btn.setFont(QFont("Montserrat", 12, QFont.Weight.Bold))
dev1_btn.setStyleSheet("""
QPushButton {
background: #0A66C2;
color: white;
padding: 6px 15px;
border-radius: 5px;
border: none;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
transition: transform 0.2s;
}
QPushButton:hover {
background: #004182;
transform: scale(1.05);
}
""")
dev1_btn.clicked.connect(lambda: QDesktopServices.openUrl(QUrl("https://www.linkedin.com/in/-apoorv-/")))
dev1_btn.setToolTip("Connect with Apoorv on LinkedIn")
dev1_layout.addWidget(dev1_btn)
dev_layout.addWidget(dev1_frame)
# Developer 2
dev2_frame = QFrame()
dev2_layout = QHBoxLayout(dev2_frame)
dev2_icon = QLabel("π¨βπ»")
dev2_icon.setFont(QFont("Open Sans", 30))
dev2_icon.setStyleSheet(f"color: {'#4A90E2' if not self.is_dark_mode else '#fc6a03'};")
dev2_layout.addWidget(dev2_icon)
dev2_info = QLabel("Yash Verdhan")
dev2_info.setFont(QFont("Open Sans", 16, QFont.Weight.Medium))
dev2_info.setStyleSheet(f"color: {'#333' if not self.is_dark_mode else '#E0E7FF'};")
dev2_layout.addWidget(dev2_info)
dev2_btn = QPushButton("π LinkedIn")
dev2_btn.setFont(QFont("Montserrat", 12, QFont.Weight.Bold))
dev2_btn.setStyleSheet("""
QPushButton {
background: #0A66C2;
color: white;
padding: 6px 15px;
border-radius: 5px;
border: none;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
transition: transform 0.2s;
}
QPushButton:hover {
background: #004182;
transform: scale(1.05);
}
""")
dev2_btn.clicked.connect(lambda: QDesktopServices.openUrl(QUrl("https://www.linkedin.com/in/yash-verdhan")))
dev2_btn.setToolTip("Connect with Yash on LinkedIn")
dev2_layout.addWidget(dev2_btn)
dev_layout.addWidget(dev2_frame)
help_layout.addWidget(dev_section)
# FAQ Section
faq_section = QFrame()
faq_section.setStyleSheet(f"""
background: {'#F9FAFB' if not self.is_dark_mode else '#313131'};
border-radius: 10px;
padding: 15px;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
""")
faq_layout = QVBoxLayout(faq_section)
faq_title = QLabel("Frequently Asked Questions")
faq_title.setFont(QFont("Montserrat", 18, QFont.Weight.Bold))
faq_title.setStyleSheet(f"color: {'#333' if not self.is_dark_mode else '#E0E7FF'}; padding-bottom: 10px;")
faq_layout.addWidget(faq_title, alignment=Qt.AlignmentFlag.AlignCenter)
# Updated FAQs with Founder Mention and Security
faqs = [
("Who is ThinkTech?",
"ThinkTech is the brainchild of founder Apoorv Gupta, turning visions into virtual reality and dreams into designs. "
"From vision to virtual, from dream to designβThinkTech is the future, in every line. In every code we write, "
"in every algorithm we create, we unlock new possibilities. We donβt just thinkβwe think tech."),
("How do I reset my master password?",
"Head to 'Forgot Password?' on the login screen, pick 'Face Scan', 'Device Fingerprint', or 'Trusted Contact', "
"and follow the steps to set a new password. ThinkTechβs got your back!"),
("What if my face scan fails?",
"Ensure good lighting and face the camera straight on. If itβs still not working, switch to another recovery "
"option like Device Fingerprint or Trusted Contactβour tech adapts to you."),
("How do I add a new credential?",
"Log in, hit 'Add Credential', enter the website, username, password, and category, then click 'Save'. "
"Itβs that simple with ThinkTechβs intuitive design!"),
("How does PassGuard keep my data safe?",
"Your dataβs locked down with top-tier encryption: AES-256 for passwords and RSA for key protection. "
"In every code we write at ThinkTech, we prioritize your securityβstored safely in Firebase."),
("Whatβs AES and RSA encryption?",
"AES-256 is a super-strong symmetric cipher that scrambles your passwords with your master password. "
"RSA uses a public-private key pair to secure your private key. Together, theyβre the backbone of PassGuardβs "
"unbreakable security, crafted by ThinkTech."),
("Can I trust Firebase with my data?",
"Absolutely! Firebase is a secure, Google-backed cloud platform. Paired with ThinkTechβs AES and RSA encryption, "
"your data stays untouchableβeven we canβt peek inside!"),
("How do I set up a trusted contact?",
"During setup, enter a friendβs username in the 'Trusted Contact' field. Theyβll get a unique 44-character recovery "
"key in their Settings page, encrypted with their public key. They can share it with you securely (e.g., in person "
"or via encrypted chat) if you need to recover your account."),
("How do I use a trusted contact to recover my account?",
"Ask your trusted contact to log in, go to Settings, and copy their recovery key for your username. Then, in "
"'Forgot Password?', select 'Trusted Contact', paste that 44-character key, and submitβitβll unlock your account."),
("How do I contact support?",
"Hit the LinkedIn buttons above to reach the ThinkTech crew directly. Weβre here to help unlock any possibility!")
]
for question, answer in faqs:
q_btn = QPushButton(f"β {question}")
q_btn.setFont(QFont("Open Sans", 14))
q_btn.setStyleSheet(f"""
QPushButton {{
background: {'#E0E7FF' if not self.is_dark_mode else '#3A3A3A'};
color: {'#333' if not self.is_dark_mode else '#E0E7FF'};
padding: 10px;
border-radius: 5px;
text-align: left;
border: none;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
transition: transform 0.2s;
}}
QPushButton:hover {{
background: {'#D1D9FF' if not self.is_dark_mode else '#4A4A4A'};
transform: scale(1.02);
}}
""")
q_btn.setCursor(Qt.CursorShape.PointingHandCursor)
a_label = QLabel(answer)
a_label.setFont(QFont("Open Sans", 12))
a_label.setStyleSheet(f"color: {'#555' if not self.is_dark_mode else '#B0B0B0'}; padding: 5px 15px;")
a_label.setWordWrap(True)
a_label.hide()
q_btn.clicked.connect(lambda checked, btn=q_btn, lbl=a_label: self.toggle_faq(btn, lbl))
faq_layout.addWidget(q_btn)
faq_layout.addWidget(a_label)
help_layout.addWidget(faq_section)
# Back Button with icon and hover effect
back_btn = QPushButton("β¬
οΈ Back")
back_btn.setFont(QFont("Montserrat", 12, QFont.Weight.Bold))
back_btn.setStyleSheet("""
QPushButton {
background: #4A90E2;
color: white;
padding: 8px 20px;
border-radius: 5px;
border: none;
box-shadow: 0 2px 4px rgba(0,0,0,0.15);
transition: transform 0.2s;
}
QPushButton:hover {
background: #357ABD;
transform: scale(1.05);
}
""")
back_btn.clicked.connect(self.show_settings if hasattr(self, 'user_id') and self.user_id else self.show_login)
back_btn.setToolTip("Return to previous screen")
help_layout.addWidget(back_btn, alignment=Qt.AlignmentFlag.AlignCenter)
# Scrollable Area
from PyQt6.QtWidgets import QScrollArea
scroll = QScrollArea()
scroll.setWidgetResizable(True)
scroll.setWidget(help_container)
scroll.setStyleSheet(f"""
QScrollArea {{
background: {'#FFFFFF' if not self.is_dark_mode else '#2D2D2D'};
border: none;
border-radius: 10px;
}}
QScrollBar:vertical {{
border: none;
background: {'#E0E7FF' if not self.is_dark_mode else '#3A3A3A'};
width: 10px;
margin: 0px 0px 0px 0px;
border-radius: 5px;
}}
QScrollBar::handle:vertical {{
background: {'#4A90E2' if not self.is_dark_mode else '#fc6a03'};
border-radius: 5px;
}}
""")
self.content_layout.addWidget(scroll, stretch=1)
def toggle_faq(self, button, label):
"""Toggle FAQ answer visibility"""
if label.isVisible():
label.hide()
button.setStyleSheet(f"""
background: {'#E0E7FF' if not self.is_dark_mode else '#3A3A3A'};
color: {'#333' if not self.is_dark_mode else '#E0E7FF'};
padding: 10px;
border-radius: 5px;
text-align: left;
""")
else:
label.show()
button.setStyleSheet(f"""
background: {'#4A90E2' if not self.is_dark_mode else '#fc6a03'};
color: white;
padding: 10px;
border-radius: 5px;
text-align: left;
""")
def show_settings(self):
self.clear_content()
self.content_layout.setSpacing(20) # Tightened from 25 for a cozier feel
# Title with gradient flair
title = QLabel("Settings")
title.setFont(QFont("Montserrat", 48, QFont.Weight.Bold))
title.setStyleSheet(f"""
color: {'#4A90E2' if not self.is_dark_mode else '#fc6a03'};
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
padding: 5px 20px;
""")
self.content_layout.addWidget(title, alignment=Qt.AlignmentFlag.AlignCenter)
# Account section with a sleek frame
account_frame = QFrame()
account_frame.setStyleSheet(f"""
background: {'#FFFFFF' if not self.is_dark_mode else '#313131'};
border-radius: 12px;
box-shadow: 0 3px 8px rgba(0,0,0,0.1);
padding: 15px;
margin: 5px 0; # Tightened from 10px
""")
account_layout = QHBoxLayout(account_frame)
account_icon = QLabel("π€")
account_icon.setFont(QFont("Open Sans", 50))
account_icon.setStyleSheet(f"color: {'#4A90E2' if not self.is_dark_mode else '#fc6a03'};")
account_layout.addWidget(account_icon)
account_label = QLabel(f"{self.user_id}")
account_label.setFont(QFont("Open Sans", 38, QFont.Weight.Medium))
account_label.setStyleSheet(f"color: {'#333' if not self.is_dark_mode else '#E0E7FF'};")
account_layout.addWidget(account_label)
self.content_layout.addWidget(account_frame, alignment=Qt.AlignmentFlag.AlignCenter)
# Recovery Keys section with a subtle background
doc = users_ref.document(self.user_id).get()
print(f"User ID: {self.user_id}, Doc exists: {doc.exists}")
recovery_keys = doc.to_dict().get("recovery_keys", {})
print(f"Raw recovery keys: {recovery_keys}")
if recovery_keys and hasattr(self, 'private_key') and self.private_key:
keys_frame = QFrame()
keys_frame.setStyleSheet(f"""
background: {'#E0E7FF' if not self.is_dark_mode else '#3A3A3A'};
border-radius: 10px;
padding: 15px;
box-shadow: 0 2px 6px rgba(0,0,0,0.05);
margin: 5px 0; # Tightened from 10px
""")
keys_layout = QVBoxLayout(keys_frame)
keys_label = QLabel("Your Recovery Keys (Share with friends if needed):")
keys_label.setFont(QFont("Open Sans", 14, QFont.Weight.Bold))
keys_label.setStyleSheet(f"color: {'#333' if not self.is_dark_mode else '#E0E7FF'}; padding-bottom: 8px;")
keys_layout.addWidget(keys_label)
for requester_id, encrypted_key in recovery_keys.items():
print(
f"Decrypting key for {requester_id}: {encrypted_key[:20]}... with private key: {self.private_key[:20]}...")
recovery_key = decrypt_with_rsa(encrypted_key, self.private_key)
if recovery_key:
key_str = base64.b64encode(recovery_key).decode()
print(f"Decrypted key for {requester_id}: {key_str}")
key_frame = QFrame()
key_frame.setStyleSheet(f"""
background: {'#FFFFFF' if not self.is_dark_mode else '#4A4A4A'};
border-radius: 8px;
padding: 10px;
margin: 3px 0; # Tightened from 5px
""")
key_layout = QHBoxLayout(key_frame)
key_text = QLabel(f"For {requester_id}: {key_str}")
key_text.setFont(QFont("Open Sans", 11))
key_text.setStyleSheet(f"color: {'#555' if not self.is_dark_mode else '#B0B0B0'};")
key_layout.addWidget(key_text)
copy_btn = QPushButton("Copy")
copy_btn.setFont(QFont("Montserrat", 10, QFont.Weight.Bold))
copy_btn.setStyleSheet("""
background: #10B981;
color: white;
padding: 6px 15px;
border-radius: 5px;
border: none;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
""")
copy_btn.clicked.connect(lambda checked, k=key_str: QApplication.clipboard().setText(k))
key_layout.addWidget(copy_btn)
keys_layout.addWidget(key_frame)
else:
print(f"Failed to decrypt key for {requester_id}")
error_label = QLabel(f"Couldnβt decrypt key for {requester_id}")
error_label.setFont(QFont("Open Sans", 10))
error_label.setStyleSheet(f"color: {'#FF6B6B' if not self.is_dark_mode else '#FF8787'};")
keys_layout.addWidget(error_label)
self.content_layout.addWidget(keys_frame, alignment=Qt.AlignmentFlag.AlignCenter)
else:
no_keys_label = QLabel("No recovery keys available yet.")
no_keys_label.setFont(QFont("Open Sans", 12, QFont.Weight.Medium))
no_keys_label.setStyleSheet(f"color: {'#888' if not self.is_dark_mode else '#A0A0A0'}; padding: 8px;")
self.content_layout.addWidget(no_keys_label, alignment=Qt.AlignmentFlag.AlignCenter)
# Buttons section with icons and hover scale effect at the bottom
theme_btn = QPushButton(f"π Switch to {'Dark' if not self.is_dark_mode else 'Light'} Mode")
theme_btn.setFont(QFont("Montserrat", 14, QFont.Weight.Bold))
theme_btn.setStyleSheet("""
QPushButton {
background: #4A90E2;
color: white;
padding: 12px 30px;
border-radius: 8px;
border: none;
box-shadow: 0 2px 6px rgba(0,0,0,0.15);
transition: transform 0.2s;
}
QPushButton:hover {
background: #357ABD;
transform: scale(1.05);
}
""")
theme_btn.clicked.connect(self.toggle_theme)
self.content_layout.addWidget(theme_btn, alignment=Qt.AlignmentFlag.AlignCenter)
logout_btn = QPushButton("πͺ Logout")
logout_btn.setFont(QFont("Montserrat", 14, QFont.Weight.Bold))
logout_btn.setStyleSheet("""
QPushButton {
background: #FF6B6B;
color: white;
padding: 12px 30px;
border-radius: 8px;
border: none;
box-shadow: 0 2px 6px rgba(0,0,0,0.15);
transition: transform 0.2s;
}
QPushButton:hover {
background: #E55A5A;
transform: scale(1.05);
}
""")
logout_btn.setToolTip("Log out of your account")
logout_btn.clicked.connect(self.logout)
self.content_layout.addWidget(logout_btn, alignment=Qt.AlignmentFlag.AlignCenter)
contact_btn = QPushButton("π Contact Developer")
contact_btn.setFont(QFont("Montserrat", 14, QFont.Weight.Bold))
contact_btn.setStyleSheet("""
QPushButton {
background: #10B981;
color: white;
padding: 12px 30px;
border-radius: 8px;
border: none;
box-shadow: 0 2px 6px rgba(0,0,0,0.15);
transition: transform 0.2s;
}
QPushButton:hover {
background: #059669;
transform: scale(1.05);
}
""")
contact_btn.clicked.connect(lambda: QDesktopServices.openUrl(QUrl("https://www.linkedin.com/in/-apoorv-/")))
contact_btn.setToolTip("Reach out to the developer")
self.content_layout.addWidget(contact_btn, alignment=Qt.AlignmentFlag.AlignCenter)
about_btn = QPushButton("βΉοΈ About PassGuard")
about_btn.setFont(QFont("Montserrat", 14, QFont.Weight.Bold))
about_btn.setStyleSheet("""
QPushButton {
background: #6B7280;
color: white;
padding: 12px 30px;
border-radius: 8px;
border: none;
box-shadow: 0 2px 6px rgba(0,0,0,0.15);
transition: transform 0.2s;
}
QPushButton:hover {
background: #4B5563;
transform: scale(1.05);
}
""")
about_btn.clicked.connect(self.show_about)
about_btn.setToolTip("Learn more about PassGuard")
self.content_layout.addWidget(about_btn, alignment=Qt.AlignmentFlag.AlignCenter)
def eventFilter(self, obj, event):
if event.type() in (QEvent.Type.MouseMove, QEvent.Type.KeyPress, QEvent.Type.MouseButtonPress):
self.reset_inactivity_timer()
if event.type() == QEvent.Type.KeyPress and event.key() == Qt.Key.Key_Escape:
if self.isFullScreen():
self.showNormal()
else:
self.showFullScreen()
return True
return super().eventFilter(obj, event)
def reset_inactivity_timer(self):
if hasattr(self, 'user_id') and self.user_id:
self.inactivity_timer.start()
def clear_content(self):
# Delete all widgets
for widget in self.content.findChildren(QWidget):
widget.deleteLater()
# Remove all stretch items from the layout
for i in reversed(range(self.content_layout.count())):
item = self.content_layout.itemAt(i)
if item.spacerItem(): # Check if the item is a stretch (spacer)
self.content_layout.removeItem(item)
def check_login_before_action(self, action):
if not hasattr(self, 'user_id') or self.user_id is None:
self.show_not_logged_in_message()
else:
action()
def show_not_logged_in_message(self):
self.clear_content()
message = QLabel("Please log in to access this feature.")
message.setFont(QFont("Open Sans", 14))
message.setStyleSheet("color: #FF6B6B; padding: 20px;")
self.content_layout.addWidget(message, alignment=Qt.AlignmentFlag.AlignCenter)
def show_login(self):
self.clear_content()
self.content_layout.setSpacing(20)
# Create a container to group title and login frame
container = QFrame()
container.setObjectName("loginContainer") # For animation
container_layout = QVBoxLayout(container)
container_layout.setSpacing(10)
# Title with gradient flair
title = QLabel("Welcome Back")
title.setFont(QFont("Montserrat", 50, QFont.Weight.Bold))
title.setStyleSheet(f"""
color: {'#4A90E2' if not self.is_dark_mode else '#fc6a03'};
padding: 5px 15px;
""")
container_layout.addWidget(title, alignment=Qt.AlignmentFlag.AlignCenter)
# Frame for all login elements
login_frame = QFrame()
login_frame.setFixedWidth(400)
login_frame.setFixedHeight(600) # Slightly reduced height for better balance
login_frame.setStyleSheet(f"""
background: {'#F9FAFB' if not self.is_dark_mode else '#3A3A3A'};
border-radius: 15px;
padding: 20px;
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
""")
login_layout = QVBoxLayout(login_frame)
login_layout.setSpacing(25) # Increased spacing for better breathing room
# Input fields with icons
self.entries = {}
for label, key, echo, placeholder, icon in [
("Username", "username", QLineEdit.EchoMode.Normal, "Enter your username", "π€"),
("Master Password", "password", QLineEdit.EchoMode.Password, "Enter your master password", "π")
]:
input_frame = QFrame()
input_frame.setStyleSheet(f"""
background: {'#FFFFFF' if not self.is_dark_mode else '#4A4A4A'};
border: 1px solid {'#E0E7FF' if not self.is_dark_mode else '#5A5A5A'};
border-radius: 8px;
padding: 5px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
""")
input_layout = QHBoxLayout(input_frame)
# Icon
icon_label = QLabel(icon)
icon_label.setFont(QFont("Open Sans", 20))
icon_label.setStyleSheet(f"color: {'#4A90E2' if not self.is_dark_mode else '#fc6a03'}; padding: 0 10px;")
input_layout.addWidget(icon_label)
# Label and Entry
input_sub_layout = QVBoxLayout()
lbl = QLabel(label)
lbl.setFont(QFont("Open Sans", 12))
lbl.setStyleSheet(f"color: {'#333' if not self.is_dark_mode else '#E0E7FF'};")
input_sub_layout.addWidget(lbl)
entry = QLineEdit()
entry.setFont(QFont("Open Sans", 14))
entry.setStyleSheet(f"""
background: {'#FFFFFF' if not self.is_dark_mode else '#4A4A4A'};
border: none;
padding: 8px;
border-radius: 5px;
color: {'#333' if not self.is_dark_mode else '#E0E7FF'};
""")
entry.setPlaceholderText(placeholder)
entry.setEchoMode(echo)
palette = entry.palette()
palette.setColor(QPalette.ColorRole.PlaceholderText, QColor("#888"))
entry.setPalette(palette)
input_sub_layout.addWidget(entry)
input_layout.addLayout(input_sub_layout)
login_layout.addWidget(input_frame)
self.entries[key] = entry
# Add stretch to position buttons lower
login_layout.addStretch(1)
# Button group in a sub-layout
button_frame = QFrame()
button_layout = QVBoxLayout(button_frame)
button_layout.setSpacing(35)
# Login Button with icon and hover effect
login_btn = QPushButton("π Login")
login_btn.setFont(QFont("Montserrat", 16, QFont.Weight.Bold))
login_btn.setMinimumHeight(40)
login_btn.setStyleSheet("""
QPushButton {
background: #4A90E2;
color: white;
padding: 0px 30px;
border-radius: 8px;
border: none;
box-shadow: 0 2px 6px rgba(0,0,0,0.15);
transition: transform 0.2s;
}
QPushButton:hover {
background: #357ABD;
transform: scale(1.05);
}
""")
login_btn.clicked.connect(self.login)
login_btn.setToolTip("Log in to your account")
button_layout.addWidget(login_btn, alignment=Qt.AlignmentFlag.AlignCenter)
# Forgot Password Button with icon and hover effect
forgot_btn = QPushButton("β Forgot Password?")
forgot_btn.setFont(QFont("Montserrat", 12, QFont.Weight.Bold))
forgot_btn.setMinimumHeight(40)
forgot_btn.setStyleSheet("""
QPushButton {
background: #FFD166;
color: #333333;
padding: 8px 20px;
border-radius: 5px;
border: none;
box-shadow: 0 2px 4px rgba(0,0,0,0.15);
transition: transform 0.2s;
}
QPushButton:hover {
background: #FFC107;
transform: scale(1.05);
}
""")
forgot_btn.clicked.connect(self.show_recovery_options)
forgot_btn.setToolTip("Recover your account")
button_layout.addWidget(forgot_btn, alignment=Qt.AlignmentFlag.AlignCenter)
login_layout.addWidget(button_frame, alignment=Qt.AlignmentFlag.AlignCenter)
# PassGuard Logo Image
logo_label = QLabel()
logo_path = os.path.join(get_base_path(), "logo.png")
logo_pixmap = QPixmap(logo_path)
if not logo_pixmap.isNull():
logo_pixmap = logo_pixmap.scaled(200, 200, Qt.AspectRatioMode.KeepAspectRatio,
Qt.TransformationMode.SmoothTransformation)
logo_label.setPixmap(logo_pixmap)
else:
logo_label.setText("PassGuard Logo")
logo_label.setFont(QFont("Montserrat", 16, QFont.Weight.Bold))
logo_label.setStyleSheet(f"color: {'#4A90E2' if not self.is_dark_mode else '#fc6a03'};")
logo_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
login_layout.addWidget(logo_label, alignment=Qt.AlignmentFlag.AlignCenter)
login_layout.addStretch(1)
container_layout.addWidget(login_frame, alignment=Qt.AlignmentFlag.AlignCenter)
self.content_layout.addStretch(2)
self.content_layout.addWidget(container, alignment=Qt.AlignmentFlag.AlignCenter)
self.content_layout.addStretch(1)
# Add fade-in animation
animation = QPropertyAnimation(container, b"windowOpacity", self)
animation.setDuration(1000) # 1 second
animation.setStartValue(0.0)
animation.setEndValue(1.0)
animation.setEasingCurve(QEasingCurve.Type.InOutQuad)
animation.start()
def show_recovery_options(self):
self.clear_content()
self.content_layout.setSpacing(20) # Consistent spacing like other pages
# Title with gradient flair
title = QLabel("Recover Your Account")
title.setFont(QFont("Montserrat", 60, QFont.Weight.Bold))
title.setStyleSheet(f"""
color: {'#4A90E2' if not self.is_dark_mode else '#fc6a03'};
padding: 5px 15px;
""")
self.content_layout.addWidget(title, alignment=Qt.AlignmentFlag.AlignCenter)
# Container for recovery options
container = QFrame()
container.setStyleSheet(f"""
background: {'#F9FAFB' if not self.is_dark_mode else '#3A3A3A'};
border-radius: 15px;
padding: 20px;
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
""")
container_layout = QVBoxLayout(container)
container_layout.setSpacing(0)
user_id = self.entries["username"].text() if hasattr(self, 'entries') and "username" in self.entries else ""
if not user_id:
error_frame = QFrame()
error_frame.setStyleSheet(f"""
background: {'#FFF1F1' if not self.is_dark_mode else '#4A2A2A'};
border-radius: 8px;
padding: 10px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
""")
error_layout = QVBoxLayout(error_frame)
error = QLabel("Please enter your username first.")
error.setFont(QFont("Open Sans", 12))
error.setStyleSheet("color: #FF6B6B;")
error.setAlignment(Qt.AlignmentFlag.AlignCenter)
error_layout.addWidget(error)
container_layout.addWidget(error_frame, alignment=Qt.AlignmentFlag.AlignCenter)
else:
options = [
("π Face Scan", lambda: self.recover_with_face(user_id), "Use your webcam to scan your face"),
("π± Device Fingerprint", lambda: self.recover_with_device(user_id), "Verify using this device"),
("π₯ Trusted Contact", lambda: self.recover_with_contact(user_id), "Enter key from trusted contact")
]
for text, cmd, desc in options:
btn_frame = QFrame()
btn_layout = QVBoxLayout(btn_frame)
btn_layout.setSpacing(5)
# Recovery option button with icon and hover effect
btn = QPushButton(text)
btn.setFont(QFont("Montserrat", 14, QFont.Weight.Bold))
btn.setStyleSheet("""