Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- """Imporing Tkinter(GUI),hashlib(SHA1,MD5),pyperclip(Copy;Paste)"""
- from Tkinter import *
- import hashlib
- import pyperclip
- """Main password"""
- def master_password():
- w = open("master","w")
- w.close()
- master_password.top = Toplevel()
- master_password.top.title("Welcome to SafeSenha!")
- Label(master_password.top,text="Welcome to SafeSenha, this is a non safe,(ironic because of the name)\nand still in heavy development applicaton.").grid(row=0,column=0,columnspan=4)
- Label(master_password.top,text="Enter your password:").grid(row=1,column=0)
- master_password.master_password_entry = Entry(master_password.top)
- master_password.master_password_entry.grid(row=1,column=1)
- Button(master_password.top,text="Submit",command=write_master_password).grid(row=2,column=1)
- def write_master_password():
- msg = master_password.master_password_entry.get()
- master_password.top.destroy()
- w = open("master","w")
- w.write(str(msg))
- w.close()
- """Check main password."""
- try:
- open("master","r")
- except:
- master_password()
- """Function used to replace the line number in dict_currline , to userspw.py"""
- """Writing down a text file with the line that the program should write
- the next time that opens, was the only way i found out"""
- def replace_line(file_name, line_num, text):
- lines = open(file_name, 'r').readlines()
- lines[line_num] = text
- out = open(file_name, 'w')
- out.writelines(lines)
- out.close()
- """First thing my program trys to do is open the file userspw,
- if this file wasn't created yet.. it will be! It will wrote a dictionary
- with 100 blank lines."""
- try:
- import userspw
- except:
- newline = "\n"
- mysenha = open("userspw.py", "a")
- mysenha.write("updic0 = {" + newline * 100 + "}")
- mysenha.close()
- """Checks if dict_currline is created."""
- try:
- r = open("dict_currline","r")
- r.close()
- except:
- create = open("dict_currline","w")
- create.write("0")
- create.close()
- """Exit function for menu file"""
- def exit():
- root.quit()
- """New account function for menu file"""
- def new_account():
- top = Toplevel(width=25, height=25, bd=3, relief=RIDGE) #Subframe that opens when addcount is pressed.
- top.title("Add account") #Title
- introduction = Label(top, text="=========== Be welcome to Database account adder! ==========") #Welcoming
- introduction.grid(row=0, column=0, columnspan=4) #Putting on the grid
- instructions0 = Label(top, text="Create new account:")
- instructions0.grid(row=1, column=1, columnspan=1) #Putting on the grid
- instructions1 = Label(top, text="New Username:")
- instructions1.grid(row=2, column=0) #Putting on the grid
- instructions2 = Label(top, text="New Password:")
- instructions2.grid(row=3, column=0) #Putting on the grid
- new_account.enter_new_username = Entry(top) # This is a global variable, so we can use it in another func
- new_account.enter_new_username.grid(row=2, column=1) #Putting on the grid
- new_account.enter_new_password = Entry(top)
- new_account.enter_new_password.grid(row=3, column=1) #Putting on the grid
- submit_account = Button(top, text="Submit", command=new_account_code) # Redirecting us to new_account_code function
- submit_account.grid(row=4, column=1) #Putting on the grid
- new_account.text = Text(top, width=64, height=5, wrap=WORD) # Text block where change logs will be inserted.
- new_account.text.grid(row=5, column=0, columnspan=4) #Putting on the grid
- """Happens whenver someone trys to add an account."""
- def new_account_code():
- with open("dict_currline", "r") as dictline: # First open "dictline" to check our current ditcionary line.
- line = int(dictline.read()) # Then assign it to a variable
- line = line + 1 # The value of the variable plus one, so we do not overwrite accounts in the dictionary.
- with open("dict_currline", "w") as dictlinepls1: #Open our dict_currline to inform our current using line.
- dictlinepls1.write(str(line))
- #Then, creating a message variable that makes sure that the username and password are introduced in the correct format to the dict.
- message = "'" + new_account.enter_new_username.get() + "'" + ":" + "'" + new_account.enter_new_password.get() + "'" + ","
- #Delete text outputed before so everything is clean.
- new_account.text.delete(0.0, END)
- #Informing the user that everything went well adding the account.
- new_account.text.insert(0.0, "Account sucessfuly added. Make sure to restart the program before you use it! :)")
- #Finaly using the function above to replace the line that is in our text file, to the file userspw.py, with the message containing
- #username and password on it, with the correct format to put on the dictionary.
- replace_line("userspw.py", line, message)
- """SHA1_SUM encrypter function for resources in menu"""
- """This function and the one bellow,basicaly, take a string input by the user, we use the hashlib to turn it
- into a sha1 hash, and retrieve that hash to the user."""
- def sha1_sum_interface():
- top = Toplevel(width=25, height=25, bg="Grey", bd=3, relief=RIDGE)
- top.title("SHA1 Encrypter")
- introduction = Label(top, text="============= Be welcome to SHA1 encrypter! ============")
- introduction.grid(row=0, column=0, columnspan=3)
- instructions = Label(top, text="String you want to convert:")
- instructions.grid(row=1, column=0, columnspan=2, sticky=W)
- sha1_sum_interface.sha1entry = Entry(top)
- sha1_sum_interface.sha1entry.grid(row=1, column=2, sticky=W)
- submit_button = Button(top, text="Submit", command=sha1_sum_code)
- submit_button.grid(row=2, column=1, sticky=E)
- dimiss_button = Button(top, text="Dimiss", command=top.destroy)
- dimiss_button.grid(row=2, column=2, sticky=W)
- copy_button = Button(top, text="Copy", command=copy_hash_sha1)
- copy_button.grid(row=2, column=1, sticky=W)
- sha1_sum_interface.sha1_text = Text(top, width=64, height=5, wrap=WORD)
- sha1_sum_interface.sha1_text.grid(row=4, column=0, columnspan=4)
- def sha1_sum_code():
- string = sha1_sum_interface.sha1entry.get()
- sha1_sum_code.sha1_hash = hashlib.sha1(string)
- sha1_sum_code.sha1_hash = sha1_sum_code.sha1_hash.hexdigest()
- sha1_sum_interface.sha1_text.delete(0.0, END)
- sha1_sum_interface.sha1_text.insert(0.0, sha1_sum_code.sha1_hash)
- """SHA1COPY BUTTON"""
- def copy_hash_sha1():
- pyperclip.copy(sha1_sum_code.sha1_hash)
- sha1_sum_interface.sha1_text.insert(0.0, "\n SHA1 string has has been sucessifuly copied.")
- """MD5_encrypter function for resources in menu"""
- """Same as Sha1 but in MD5"""
- def md5_interface():
- top = Toplevel(width=25, height=25, bd=3, relief=SUNKEN)
- top.title("MD5 Encrypter")
- introduction = Label(top, text="============= Be welcome to MD5 encrypter! =============")
- introduction.grid(row=0, column=0, columnspan=3)
- instructions = Label(top, text="String you want to convert:")
- instructions.grid(row=1, column=0, columnspan=2, sticky=W)
- md5_interface.md5entry = Entry(top)
- md5_interface.md5entry.grid(row=1, column=2, sticky=W)
- submit_button = Button(top, text="Submit", command=md5_code)
- submit_button.grid(row=2, column=1, sticky=E)
- dimiss_button = Button(top, text="Dimiss", command=top.destroy)
- dimiss_button.grid(row=2, column=2, sticky=W)
- copy_button = Button(top, text="Copy", command=copy_hash_md5)
- copy_button.grid(row=2, column=1, sticky=W)
- md5_interface.md5_text = Text(top, width=64, height=5, wrap=WORD)
- md5_interface.md5_text.grid(row=4, column=0, columnspan=4)
- def md5_code():
- string = md5_interface.md5entry.get()
- md5_code.md5_hash = hashlib.md5(string)
- md5_code.md5_hash = md5_code.md5_hash.hexdigest()
- md5_interface.md5_text.delete(0.0, END)
- md5_interface.md5_text.insert(0.0, md5_code.md5_hash)
- """MD5 COPY BUTTON"""
- def copy_hash_md5():
- pyperclip.copy(md5_code.md5_hash)
- md5_interface.md5_text.insert(0.0, "\n MD5 string has has been sucessifuly copied.")
- """Credits function, in about menu"""
- def credits():
- top = Toplevel(width=15, height=3, bg="Grey", bd=3, relief=GROOVE)
- top.title("About this application...")
- msg = Message(top,
- text="Thanks for using SenhaSafe! This program was made for eductional purposes by krec01.\n Be HAPPY <3")
- msg.pack()
- dimiss_button = Button(top, text="Dimiss", command=top.destroy)
- dimiss_button.pack()
- class Application(Frame):
- def __init__(self, master):
- Frame.__init__(self, master)
- self.grid()
- self.master_password()
- """Master password request menu"""
- def master_password(self):
- """Instructions"""
- self.master_instructions = Label(self, text="Introduce the master password to gain acess:")
- self.master_instructions.grid(row=0, column=0)
- """Credits"""
- Label(self, text="Made by krec01, current version- v0.01").grid(row=10, column=0)
- """Password entry gap with * chars"""
- self.master_entry = Entry(self, show="*", width=25)
- self.master_entry.grid(row=0, column=1)
- """Checkbutton for plain test, leads to plain_test function"""
- self.plain_test = BooleanVar()
- Checkbutton(self, text="Show plain test", variable=self.plain_test, command=self.plain_test_retrieve).grid(
- row=1, column=0)
- """Submit button, leading to master_check function"""
- self.submit_master = Button(self, text="Submit", command=self.master_check)
- self.submit_master.grid(row=1, column=1, columnspan=1)
- """Area where text is inserted"""
- self.text = Text(self, width=71, height=6)
- self.text.grid(row=5, column=0, columnspan=3)
- """Function that checks master password whenever submit button is pressed. Removes widget is pw is correct"""
- def master_check(self):
- r = open("master","r")
- pword = str(r.read())
- if self.master_entry.get() == pword:
- self.text.delete(0.0, END)
- self.text.insert(0.0, "\nCorrect password! Acess Garanted")
- self.master_entry.grid_remove()
- self.submit_master.grid_remove()
- self.master_instructions.grid_remove()
- """Leading to create_widgets function"""
- return self.create_widgets()
- else:
- self.text.delete(0.0, END)
- self.text.insert(0.0, "Wrong Password! Acess Denied.")
- """This block is activated whenever plain_test checkbutton is pressed"""
- def plain_test_retrieve(self):
- if self.plain_test.get() == True:
- self.master_entry.config(show="")
- else:
- self.master_entry.config(show="*")
- def create_widgets(self):
- """Instructions"""
- Label(self, text="Welcome to PwBanker!").grid(row=0, column=0)
- Label(self, text="Introduce your username:").grid(row=1, column=0)
- """Checks for "userspw" file, creates one if isn't presented"""
- try:
- with open("userspw.py", "r") as senhas:
- self.text.insert(0.0, "userspw.py file detected!...")
- senhas.read()
- except:
- # mysenha = open("userspw.py", "a")
- # mysenha.write("This file passwords are protected with encryption".center(50, "#="))
- # mysenha.close()
- self.text.insert(0.0, "userspw.py file created in current directory!...")
- """Requesting password in dictionary"""
- self.username = Entry(self,width=25)
- self.username.grid(row=1, column=1)
- """Button that copys to clipboard the password"""
- self.submit_un = Button(self, text="Retrieve Password!", command=self.username_check)
- self.submit_un.grid(row=2, column=0)
- def username_check(self):
- if self.username.get() in userspw.updic0.keys():
- self.user_name = self.username.get()
- self.user_password = userspw.updic0[self.username.get()]
- self.password_message = "Username:" + " " + self.user_name + "\nPassword:" + self.user_password + "\n"
- self.text.insert(0.0, self.password_message)
- else:
- self.text.insert(0.0, "Username not found\n")
- root = Tk()
- root.title("PwBanker")
- root.geometry("500x300+200+200")
- app = Application(root)
- mymenu = Menu(root)
- root.config(menu=mymenu)
- subMenuFile = Menu(mymenu)
- mymenu.add_cascade(label="File", menu=subMenuFile)
- subMenuFile.add_command(label="New account", command=new_account)
- subMenuFile.add_command(label="Exit", command=exit)
- subMenuResources = Menu(mymenu)
- mymenu.add_cascade(label="Resources", menu=subMenuResources)
- subMenuResources.add_command(label="SHA1-SUM Encrypter", command=sha1_sum_interface)
- subMenuResources.add_command(label="MD5 Encrpyer", command=md5_interface)
- subMenuAbout = Menu(mymenu, tearoff=0)
- mymenu.add_cascade(label="About", menu=subMenuAbout)
- subMenuAbout.add_command(label="About this application...", command=credits)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement