PMCS
PMCS
PMCS
pyplot as plt
Import pickle
Import os
Import re
Try:
Cursor = mydb.cursor()
Except con.InterfaceError:
Return no_window_message(showerror, “CANONOT CONTINUE
PROGRAM”, “UNABLE TO ESTABLISH CONNECTION WITH MySQL”)
Else:
Try:
Except:
Else:
Cursor.execute(“use project”)
Finally:
Mydb.commit()
If mydb.is_connected():
# if connection is successful, create the Tables and start __main__
application
Create()
Loading()
Else:
Try:
Cursor.close()
Mydb.close()
Except con.InternalError:
Finally:
)”””
)”””
)”””
Try:
Cursor.execute(query)
Except:
Pass
Else:
Mydb.commit()
Def pass_keys() -> None:
“””creates simple encryption and deceyption keys and sets them as global
variables”””
Shuffle(chrs2)
Numbers: list[str] = []
If “@” in uname:
If uname.count(“@”) != 1 or “_” in uname or uname[0] == “@”:
Match = re.search(r”[a-zA-Z0-9.!#$%&’*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]
+(?:\.[a-zA-Z0-9-]+)*”, uname)
Copy += ekey1[char] + “ “
Return encrypted
Decrypted = copy.swapcase()[::-1]
Return decrypted
:param:
Specs: tuple[bool, bool, bool, bool]: the entries in the tuple represent
If not any(specs):
Return showwarning(“Required – Character Type”, “Select atleast one
type of character”, parent=UserVault)
Available = password = “”
For I in range(4):
Chars = list(available) * 20
Shuffle(chars)
For _ in range(length):
Try:
Index = int.from_bytes(os.urandom(2), “big”) // randint(10, 20)
Password += chars[index]
Except IndexError:
Password += choice(chars)
Password = password.translate(table)
Return password
Def no_window_message(
) -> None:
Temp_window = Tk()
Temp_window.withdraw()
Temp_window.destroy()
Color: str = “#dff3ef” # background color for Entry boxes and Text
boxes
# initialize tuples containing all required icons and image objects through
their location
ImageTk.PhotoImage(Image.open(image))
If not os.path.isfile(FILES[0]):
Return
While True:
Try:
Record = pickle.load(file)
Except EOFError:
Break
Else:
USER_COUNT += 1
USER_COUNT //= 16
Widget.destroy()
Try:
Window.destroy()
Except NameError:
Pass
Plt.close(“all”)
Def back_button(screen: Tk, window: Callable[[], None]) -> None:
Def hideshow(
) -> None:
Else:
Button.config(image=img)
Entrybox.config(show=char)
Root.destroy()
Close()
Global_vars()
Root.geometry(“548x210”)
Root.title(“Loading\N{HORIZONTAL ELLIPSIS}”)
Root.iconbitmap(ICONS[0])
Screen = Label(cursor=CURSORS[1])
Screen.place(x=0, y=0)
Screen.config(image=image)
Root.update()
Sleep(uniform(0.115, 0.225))
Screen.destroy()
Root.geometry(“450x22”)
Bar.place(x=0, y=0)
While bar[“value”] < 100:
Root.update()
Root.config(cursor=CURSORS[3])
Bar.destroy()
Intro_window()
Root.geometry(“544x544”)
Root.iconbitmap(ICONS[1])
Welcome = list(IMAGES[4:7])
Def next_window():
Try:
Del welcome[0]
Button(image=welcome[0], command=next_window,
cursor=CURSORS[0]).place(x=0, y=0)
Except IndexError:
Main_window()
Button(image=welcome[0], command=next_window,
cursor=CURSORS[0]).place(x=0, y=0)
Root.mainloop()
Empty_screen(root)
Root.geometry(“772x544”)
Root.title(“KeepMyPass”)
Root.iconbitmap(ICONS[2])
Messages = [
“Multiple Users can be created, but each will have access to one’s
own data only.”,
“Once Signed Up, you can Log in to your Secure Vault and store: {0}
Passwords {0} Contacts {0} Events”,
“If you ever forget your MasterPassword, we may be able to help you
to retrieve your lost account.”,
“A Password-Protected Admin Mode allows the developer to search for
any data!”
Label(image=IMAGES[7]).place(x=0, y=0)
For I in range(4):
Empty_screen(root)
Root.iconbitmap(ICONS[3])
Label(image=IMAGES[13]).place(x=0, y=0)
User.place(x=9, y=177.5)
Back_button(root, main_window)
“””checks the name input by the User and inputs the MasterPassword”””
Name = user.get().strip().title()
If check_name(name):
Return login_window()
Return forgot_pass()
Return user.delete(0, END)
Empty_screen(root)
Label(image=IMAGES[16]).place(x=0, y=0)
Specs = dict(width=22, bd=2, font=(“ariel”, 19, “bold”), relief=FLAT,
cursor=CURSORS[6], bg=color)
Mp1.place(x=18, y=206)
Mp2.place(x=18, y=257.5)
Hs1.place(x=333.75, y=200)
Hs2.place(x=333.75, y=252)
Values = (name, mp1, mp2, write_file, end_window)
Back_button(root, signup_window)
If not USER_COUNT:
Return False
Exists = False
Pwd_dict = pickle.load(file1)
If not (I % 16):
Name = tuple(pwd_dict.keys())[0]
If name_user == decrypt(name):
Exists = True
Break
Return exists
Def set_mpass(
) -> None:
If delete:
Mpass1.delete(0, END)
Mpass2.delete(0, END)
Return
File_func(name_user, m2)
Next_window(name_user)
“””writes fake details & User’s details and keys in the Binary Files”””
Pass_keys()
For I in range(15):
If choice(truth):
Pwds = [new_pass]
Elif choice(truth):
Else:
Pwd1 = “”.join(sample(chars, randint(8, 128)))
Global USER_COUNT
Empty_screen(root)
Root.title(“Successful!”)
Root.iconbitmap(ICONS[4])
Label(image=IMAGES[20]).place(x=0, y=0)
USER_COUNT += 1
Root.title(“Log In to KeepMyPass”)
Root.iconbitmap(ICONS[5])
Label(image=IMAGES[23]).place(x=0, y=0)
Urname.place(x=393.75, y=210)
Passwd.place(x=393.75, y=262.5)
Hs.place(x=709.5, y=256.5)
Back_button(root, main_window)
If not check_name(name_user):
Name.delete(0, END)
Pwd.delete(0, END)
Pwd_dict = pickle.load(file1)
If I % 16:
Continue
If name_user == decrypt(kname):
If passwd == decrypt(pwds[-1]):
Matched = True
Break
If matched:
Return create_vault(name_user)
Pwd.delete(0, END)
Empty_screen(root)
Messages = [
“To retrieve your lost account, your must enter any old
MasterPassword that you may remember.”,
“It doesn’t have to be the entire password, instead all you need is
any 8 matching characters.”,
“As a tip, you should choose the MasterPassword to be one you don’t
use elsewhere.”
]
Showinfo(“Forgot Password Help”, “ “.join(messages))
Label(image=IMAGES[25]).place(x=0, y=0)
Name_user.place(x=416.25, y=240)
Lastpass.place(x=416.25, y=292.5)
Back_button(root, login_window)
If not check_name(name):
If not name:
Retrieved = False
Pwd_dict = pickle.load(file1)
If I % 16:
Continue
If name != decrypt(kname):
Continue
For pwd in pwds:
If passwd in decrypt(pwd).casefold():
Retrieved = True
Break
If retrieved:
Return change_masterpass(name)
Lastpass.delete(0, END)
Def change_masterpass(name_user: str) -> None:
Empty_screen(root)
Root.iconbitmap(ICONS[7])
Label(image=IMAGES[27]).place(x=0, y=0)
Mp1.place(x=39, y=220.5)
Mp2.place(x=39, y=273)
Mp1.insert(0, “Choose a MasterPass”)
Hs1.place(x=354.75, y=214.5)
Hs2.place(x=354.75, y=267)
Pwd_dict = pickle.load(file1)
If not (I % 16):
Kname = tuple(pwd_dict.keys())[0]
If uname == decrypt(kname):
Pwd_dict[kname].append(encrypt(newpass))
Pickle.dump(pwd_dict, file3)
Os.remove(FILES[0])
Os.rename(“temp.dat”, FILES[0])
Del_recs = range(0)
Pwd_dict = pickle.load(file1)
If not (I % 16):
Kname = tuple(pwd_dict.keys())[0]
If user == decrypt(kname):
Else:
Pickle.dump((ekey1, dkey1, ekey2, dkey2), file4)
If I not in del_recs:
Pickle.dump(pwd_dict, file3)
Os.remove(name)
Os.rename(temp, name)
“””deletes the User data from the database and decrements the number
of Users”””
Global USER_COUNT
Try:
Except:
Else:
Mydb.commit()
Delete_file(name_user)
USER_COUNT -= 1
Global UserVault
Try:
UserVault.destroy()
Except NameError:
Pass
Finally:
UserVault: Tk = Toplevel(root)
UserVault.resizable(False, False)
Vault_window(user)
Main_window()
UserVault.geometry(“772x544”)
Messages = [
“You can view all the personal information in your Vault in an orderly
fashion:”,
Display_records(
Parent=UserVault, tablename=tablename,
)
Def graph(variable: str) -> None:
Plt.close(“all”)
Try:
Cursor.execute(
}[graph_number].format(repr(name))
Except:
Else:
If count in range(2):
Window_heading, graph_heading = {
0: (“Graph: Number of Passwords per App/URL”, “Frequency of
Passwords by App/URL”),
}[graph_number]
Labels = {
Plt.title(graph_heading)
Plt.get_current_fig_manager().window.wm_iconbitmap(ICONS[17])
Plt.xlabel(labels[0])
Plt.ylabel(labels[1])
Plt.grid(True)
Plt.show()
For I in range(4):
Graph_names = [
F”{n} Passwords per App/URL”, f”{n} Contacts per City”, f”{n} Events
Completed/Incomplete”, f”{n} Events per Date”
]
Logout = (lambda: askyesno(“Log Out?”, “Log Out of Secure Vault? You will
have to Log In again!”, parent=UserVault))
Menu.config(image=IMAGES[33], cursor=CURSORS[0])
Menu.place(x=0, y=474.25)
Op1.place(x=0, y=0)
Op2.place(x=699.375, y=0)
Btn.place(x=676.875, y=448.125)
) -> None:
Empty_screen(UserVault, don’t_destroy=button)
If str(button.cget(“image”)) == str(img1):
UserVault.iconbitmap(ICONS[9])
UserVault.destroy()
UserVault.destroy()
Change_masterpass(name)
UserVault.destroy()
Delete_user(name)
For I in range(3):
Button(UserVault, image=IMAGES[i+41], bd=0, command=coms[i],
cursor=CURSORS[0]).place(x=43, y=75*I + 176.25)
Else:
Vault_window(name)
Def pwd_generator(
) -> None:
Empty_screen(UserVault, don’t_destroy=button)
If str(button.cget(“image”)) == str(img1):
UserVault.iconbitmap(ICONS[10])
Button.place(x=699.375, y=0)
Messages = [
“Our Passwords are generared using Top – Class encryption
techniques.”,
If not box.get():
Root.clipboard_clear()
Root.clipboard_append(box.get())
Box.place(x=15, y=108.75)
Slider.place(x=375, y=161.25)
For I in range(4):
Variables[0].set(1)
Btn.place(x=337.5, y=468.75)
Else:
Vault_window(name)
Def gen_pass(
) -> None:
If password != “ok”:
Entrybox.config(state=NORMAL)
Entrybox.delete(0, END)
Entrybox.insert(0, password)
Entrybox.config(state=st)
Def add_info(
Name: str, buttons: list[Button, 4], button: Button, add: ImageTk, cross:
ImageTk
) -> None:
If str(button.cget(“image”)) == str(add):
UserVault.iconbitmap(ICONS[11])
Messages = [
For I in range(4):
Buttons[i].config(image=IMAGES[i+49], command=coms[i])
Button.config(image=cross)
Else:
Vault_window(name)
Def confirm(
) -> bool:
If msg:
If askokcancel(“Confirm?”, “Do you want to save the data?”,
parent=UserVault):
Else:
Return False
Else:
Return True
Empty_screen(UserVault)
UserVault.title(“Add New Passwords”)
UserVault.iconbitmap(ICONS[12])
For I in range(4):
Entries[2].insert(0, “(Optional)”)
Entries[3].insert(0.0, “(Optional)”)
Slider.place(x=551.25, y=186.75)
For I in range(4):
Variables[0].set(1)
Btn1 = Button(UserVault, image=IMAGES[54], bd=0, cursor=CURSORS[0],
command=(lambda: gen_pass(slider, variables, entries[1])))
Btn1.place(x=495, y=105)
Btn2.place(x=15, y=463.125)
If valid_username(v0):
If valid_password(v1):
Try:
Cursor.execute(
Except con.errors.IntegrityError:
Except:
Else:
Mydb.commit()
Finally:
Values[3].delete(0.0, END)
Values[2].insert(0, “(Optional)”)
Values[3].insert(0.0, “(Optional)”)
Empty_screen(UserVault)
UserVault.iconbitmap(ICONS[13])
For I in range(5):
Entries[2].insert(0, “(Optional)”)
Entries[3].insert(0, “(Optional)”)
Button.place(x=15, y=463.125)
If not v0:
If not v1:
If valid_contact(v1):
If v2:
If valid_contact(v2):
Try:
V3 = dt.strptime(v3, “%d-%m-%Y”).date()
Except ValueError:
Try:
V3 = dt.strptime(v3, “%d/%m/%Y”).date()
Except ValueError:
Try:
Cursor.execute(
Except con.errors.IntegrityError:
Except:
Else:
Mydb.commit()
Finally:
Values[2].insert(0, “(Optional)”)
Values[3].insert(0, “(Optional)”)
Empty_screen(UserVault)
UserVault.iconbitmap(ICONS[14])
For I in range(4):
Button.place(x=15, y=463.125)
If not v0:
Try:
V1 = dt.strptime(v1, “%d-%m-%Y”).date()
Except ValueError:
Try:
V1 = dt.strptime(v1, “%d/%m/%Y”).date()
Except ValueError:
V2 = f”{v2[:-2]} {v2[-2:]}”
Try:
Except ValueError:
Try:
V2 = dt.strptime(v2, “%H:%M:%S”).time()
Except ValueError:
Try:
Cursor.execute(
Except con.errors.IntegrityError:
Except:
Return showerror(“Error”, f”Sorry, we were unable to {sv_up} your
Data!”, parent=UserVault)
Else:
Mydb.commit()
Finally:
Def display_records(
Parent: Tk, tablename: str, title: str, query: str, no_records: tuple[str]
) -> None:
“””fetches and displays records from the database and helps User to
update their records”””
Try:
Window.destroy()
Except NameError:
Pass
Finally:
Try:
Cursor.execute(query)
Except:
Else:
Height = 20*count + 70
If not count:
If count != 1:
If parent is root:
Else:
Window.resizable(False, False)
Window.title(title)
Name = data[0][0].title()
If tablename == “passwords”:
If “name” in locals():
Else:
If parent is root:
Window.geometry(f”{sum(widths)+45}x{height}”)
Table.pack(side=LEFT, padx=20)
Trv = ttk.Treeview(table, columns=tuple(columns), show=”headings”,
height=str(count), selectmode=”browse”)
For I in columns:
Trv.heading(I, text=headings[i])
For I in range(len(data)):
Row = list(data[i])
If tablename == “passwords”:
If parent is root:
Check_name(row[0].title()) # updates decryption key for every
User separately
Else:
Row[1] = row[1].title()
Trv.pack()
If parent is root:
Nonlocal menu
Return
If event.num == 3:
Trv.selection_set(trv.identify_row(event.y))
Menu.tk_popup(x=event.x_root, y=event.y_root)
Trv.bind(“<Button-3>”, edit_row)
Trv.bind(“<Double-Button-1>”, edit_row)
Items = trv.item(trv.focus())[“values”]
Window.destroy()
Window.destroy()
Try:
Except:
Else:
Mydb.commit()
Attrs = {
“passwords”: (ICONS[12], IMAGES[58], 3, True, 75, save_pass, f”update
passwords set {u1} {row[1] !r}”),
}.get(table)
UserVault.iconbitmap(attrs[0])
If table != “passwords”:
If table == “events”:
For I in range(len(entries)):
Try:
Entries[i].insert(0, row[i+1])
Except TclError:
Entries[i].insert(0.0, row[i+1])
Def discard() -> None:
Return vault_window(name_user)
Vault_window(name_user)
Button(UserVault, image=IMAGES[61], cursor=CURSORS[0], bd=0,
command=update).place(x=8.25, y=469.5)
Global admin
If not askyesno(“Log Users Out?”, “Running Admin Mode will log all users
out. Still continue?”):
Return
Try:
Plt.close(“all”)
UserVault.destroy()
Except NameError:
Pass
Try:
Admin.destroy()
Except NameError:
Pass
Finally:
Admin = Toplevel(root)
Admin.geometry(“534x96”)
Admin.resizable(False, False)
Admin.title(“Access Admin Mode”)
Admin.iconbitmap(ICONS[16])
If not all(credentials):
If credentials != CREDENTIALS:
Return showerror(“ACCESS DENIED”, “Cannot access Admin Mode”,
parent=admin)
Admin.destroy()
Admin_window()
Entries[0].place(x=242.5, y=5)
Entries[1].place(x=242.5, y=32.5)
Empty_screen(root)
Root.title(“Search Mode”)
Root.iconbitmap(ICONS[15])
Label(image=IMAGES[63]).place(x=0, y=0)
Box.place(x=15, y=106.5)
Messages = [
“Select the type of data you want to see and enter a search key.”,
“You may also see an informative Stack Plot showing Number of each
item stored per active User.”,
“An active User is one who has at least one record stored in our
database.”
Try:
Window.destroy()
Style.map(“Treeview”, background=[(“selected”, “#0078d7”)])
Except NameError:
Pass
Finally:
Main_window()
Text = box.get().strip().casefold()
Box.delete(0, END)
For I in range(3):
Var.set(“Passwords”)
Update()
M = f”’%{skey}%’”
If tablename == “passwords”:
Cond = f”username like {m} or app_url like {m} or notes like {m}”
Else:
Cond = f”evttitle like {m} or evtdate like {m} or evttime like {m} or
completed like {m}”
Display_records(
Parent=root, tablename=tablename,
Title=f”Searched {tablename.capitalize()}”,
No_records=message
“””displays the STACK PLOT: number of each item per active User in admin
mode”””
Plt.close(“all”)
Except:
Else:
Data.append(current_rows)
Users.extend(current_rows)
If user.casefold() == name.casefold():
Break
Else:
Data[i].append((user, 0))
For I in range(3):
Numbers[i].append(n)
Plt.get_current_fig_manager().window.wm_iconbitmap(ICONS[17])
Plt.xlabel(“Name of User(s)”)
Plt.ylabel(“Number of Item(s)”)
Plt.legend()
Plt.grid(True)
Plt.show()
If __name__ == “__main__”:
Connect()