File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Secure_Password_Manager/cli Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ import base64
2+
3+ def view_passwords (filename = "saved_passwords.txt" ):
4+ try :
5+ with open (filename , "r" ) as file :
6+ lines = file .readlines ()
7+
8+ # Temperory variable to store each password block info
9+ timestamp = label = encoded_password = ""
10+ included_options = ""
11+
12+ print ("\n 🔐 Saved Passwords:\n " )
13+
14+ for line in lines :
15+ line = line .strip ()
16+
17+ if line .startswith ("[" ): # Timestamp line
18+ timestamp = line .strip ("[]" )
19+
20+ elif line .startswith ("Label:" ):
21+ label = line .split ("Label:" )[1 ].strip ()
22+
23+ elif line .startswith ("Encoded Password:" ):
24+ encoded_password = line .split ("Encoded Password:" )[1 ].strip ()
25+ try :
26+ decoded_password = base64 .b64decode (encoded_password .encode ()).decode ()
27+ except Exception as e :
28+ decoded_password = f"[Error decoding password: { e } ]"
29+
30+ elif line .startswith ("Included" ):
31+ included_options = line .split ("Included -" )[1 ].strip ()
32+
33+ elif line .startswith ("-" * 10 ): # Block ends here
34+ print (f"📅 Date/Time: { timestamp } " )
35+ print (f"🏷️ Label: { label } " )
36+ print (f"🔓 Decoded Password: { decoded_password } " )
37+ print (f"🔧 Options Included: { included_options } " )
38+ print ("-" * 40 )
39+
40+ except FileNotFoundError :
41+ print ("❌ saved_passwords.txt not found." )
42+
43+ except Exception as e :
44+ print (f"❌ An error occured: { e } " )
45+
46+ # Run the function
47+ if __name__ == '__main__' :
48+ view_passwords ()
You can’t perform that action at this time.
0 commit comments