-
Notifications
You must be signed in to change notification settings - Fork 0
/
WhirlybirdManager.py
145 lines (108 loc) · 3.6 KB
/
WhirlybirdManager.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
# This is a password manager developed by Abhinav.
# The password stored is encrypted.
# It's using symmetric encryption, using a library built on top of AES algorithm.
# There are some lines which needs to be uncommented while being executed for the first time. Don't forget to comment
# them back after first execution.
from cryptography.fernet import Fernet
import tkinter as tk
import tkinter.simpledialog
from tkinter import messagebox
def write_key():
key = Fernet.generate_key()
with open("key.key", "wb") as key_file:
key_file.write(key)
def load_key():
return open("key.key", "rb").read()
def encrypt_file(filename, key):
f = Fernet(key)
with open(filename, "rb") as file:
file_data = file.read()
encrypted_data = f.encrypt(file_data)
with open(filename, "wb") as file:
file.write(encrypted_data)
def decrypt_file(filename, key):
f = Fernet(key)
with open(filename, "rb") as file:
encrypted_data = file.read()
decrypted_data = f.decrypt(encrypted_data)
with open(filename, "wb") as file:
file.write(decrypted_data)
def add():
i = 0
acc_name = input("Enter account name ")
f1 = open("acc.txt", "a")
f1.write(f"{acc_name}\n")
f1.close()
f1 = open("acc.txt", "r")
for a in f1:
i += 1
pwd = input("Enter password ")
# Uncomment it if u r running it for the first time
# !!!!!!DON'T FORGET TO COMMENT THEM BACK ONCE U HAVE
# RAN THIS PROGRAM ONCE!!!!!!!!!!
#write_key()
# <----Till here
key = load_key()
# uncomment it if u r running it for the first time
# !!!!!!DONT FORGET TO COMMENT THEM BACK ONCE U HAVE
# RAN THIS PROGRAM ONCE!!!!!!!!!!
#encrypt_file("Whirlybird.txt", key)
# <----Till here
decrypt_file("Whirlybird.txt", key)
f1 = open("Whirlybird.txt", "a")
f1.write(f"{i}{pwd}\n")
f1.close()
encrypt_file("Whirlybird.txt", key)
def display():
i = 1
f1 = open("acc.txt", "r")
for a in f1:
print(f"{i}. {a}")
i += 1
f1.close()
def read():
display()
acc_choice = int(input("Enter the serial number of account "))
key = load_key()
decrypt_file("Whirlybird.txt", key)
f1 = open("Whirlybird.txt", "r")
for a in f1:
if int(a[0]) == acc_choice:
print(a[1:])
f1.close()
encrypt_file("Whirlybird.txt", key)
while True:
tk.Tk().withdraw()
userPassword = tkinter.simpledialog.askstring("WhirlyBird: The Password Manager", "Enter Master Password:", show='*')
# Uncomment the lines below if you are running it for first time.
# !!!!!!!!!!DON'T FORGET TO COMMENT THEM BACK ONCE U HAVE
# RAN THIS PROGRAM ONCE!!!!!!!!!!
#f = open("Whirlybird.txt", "x")
#f.close()
#f = open("acc.txt","x")
#f.close()
# <------Till here
if userPassword == "Aires":
print("Access granted\n")
while True:
#top = tk.Tk
#label = Tk.Message(top, tetxvariable = "Select your opertaion", relief = tk.RAISED)
#label.pack()
#top.mainloop()
#label = top.Message()
print("\nMenu\n1.Add\n2.Read\n")
choice = int(input("Enter choice number "))
if choice == 1:
add()
else:
read()
ch = input("Do u want to continue?(y/n) ")
if ch == 'y' or ch == 'Y':
pass
else:
exit()
else:
if messagebox.askretrycancel("WhirlyBird: The Password Manager", "Wrong Password. Do you want to retry?"):
pass
else:
exit()