Advertisement
Guest User

Untitled

a guest
Jun 4th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 13.07 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. """Imporing Tkinter(GUI),hashlib(SHA1,MD5),pyperclip(Copy;Paste)"""
  4. from Tkinter import *
  5. import hashlib
  6. import pyperclip
  7.  
  8.  
  9.  
  10. """Main password"""
  11. def master_password():
  12.     w = open("master","w")
  13.     w.close()
  14.     master_password.top = Toplevel()
  15.     master_password.top.title("Welcome to SafeSenha!")
  16.     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)
  17.     Label(master_password.top,text="Enter your password:").grid(row=1,column=0)
  18.     master_password.master_password_entry = Entry(master_password.top)
  19.     master_password.master_password_entry.grid(row=1,column=1)
  20.     Button(master_password.top,text="Submit",command=write_master_password).grid(row=2,column=1)
  21.  
  22. def write_master_password():
  23.     msg = master_password.master_password_entry.get()
  24.     master_password.top.destroy()
  25.     w = open("master","w")
  26.  
  27.     w.write(str(msg))
  28.     w.close()
  29.  
  30.  
  31.  
  32. """Check main password."""
  33. try:
  34.   open("master","r")
  35. except:
  36.  master_password()
  37.  
  38.  
  39.  
  40.  
  41. """Function used to replace the line number in dict_currline , to userspw.py"""
  42. """Writing down a text file with the line that the program should write
  43. the next time that opens, was the only way i found out"""
  44.  
  45. def replace_line(file_name, line_num, text):
  46.     lines = open(file_name, 'r').readlines()
  47.     lines[line_num] = text
  48.     out = open(file_name, 'w')
  49.     out.writelines(lines)
  50.     out.close()
  51.  
  52.  
  53. """First thing my program trys to do is open the file userspw,
  54. if this file wasn't created yet.. it will be! It will wrote a dictionary
  55. with 100 blank lines."""
  56. try:
  57.     import userspw
  58. except:
  59.     newline = "\n"
  60.     mysenha = open("userspw.py", "a")
  61.     mysenha.write("updic0 = {" + newline * 100 + "}")
  62.     mysenha.close()
  63.  
  64.  
  65. """Checks if dict_currline is created."""
  66. try:
  67.     r = open("dict_currline","r")
  68.     r.close()
  69. except:
  70.     create = open("dict_currline","w")
  71.     create.write("0")
  72.     create.close()
  73.  
  74.  
  75.  
  76. """Exit function for menu file"""
  77. def exit():
  78.     root.quit()
  79.  
  80.  
  81.  
  82. """New account function for menu file"""
  83. def new_account():
  84.     top = Toplevel(width=25, height=25, bd=3, relief=RIDGE) #Subframe that opens when addcount is pressed.
  85.     top.title("Add account") #Title
  86.     introduction = Label(top, text="=========== Be welcome to Database account adder! ==========") #Welcoming
  87.     introduction.grid(row=0, column=0, columnspan=4) #Putting on the grid
  88.  
  89.     instructions0 = Label(top, text="Create new account:")
  90.     instructions0.grid(row=1, column=1, columnspan=1) #Putting on the grid
  91.     instructions1 = Label(top, text="New Username:")
  92.     instructions1.grid(row=2, column=0) #Putting on the grid
  93.     instructions2 = Label(top, text="New Password:")
  94.     instructions2.grid(row=3, column=0) #Putting on the grid
  95.  
  96.     new_account.enter_new_username = Entry(top) # This is a global variable, so we can use it in another func
  97.     new_account.enter_new_username.grid(row=2, column=1) #Putting on the grid
  98.  
  99.     new_account.enter_new_password = Entry(top)
  100.     new_account.enter_new_password.grid(row=3, column=1) #Putting on the grid
  101.  
  102.     submit_account = Button(top, text="Submit", command=new_account_code) # Redirecting us to new_account_code function
  103.     submit_account.grid(row=4, column=1) #Putting on the grid
  104.  
  105.     new_account.text = Text(top, width=64, height=5, wrap=WORD) # Text block where change logs will be inserted.
  106.     new_account.text.grid(row=5, column=0, columnspan=4) #Putting on the grid
  107.  
  108. """Happens whenver someone trys to add an account."""
  109. def new_account_code():
  110.     with open("dict_currline", "r") as dictline: # First open "dictline" to check our current ditcionary line.
  111.         line = int(dictline.read()) # Then assign it to a variable
  112.         line = line + 1 # The value of the variable plus one, so we do not overwrite accounts in the dictionary.
  113.         with open("dict_currline", "w") as dictlinepls1: #Open our dict_currline to inform our current using line.
  114.             dictlinepls1.write(str(line))
  115.  
  116.     #Then, creating a message variable that makes sure that the username and password are introduced in the correct format to the dict.
  117.     message = "'" + new_account.enter_new_username.get() + "'" + ":" + "'" + new_account.enter_new_password.get() + "'" + ","
  118.  
  119.     #Delete text outputed before so everything is clean.
  120.     new_account.text.delete(0.0, END)
  121.     #Informing the user that everything went well adding the account.
  122.     new_account.text.insert(0.0, "Account sucessfuly added. Make sure to restart the program before you use it! :)")
  123.     #Finaly using the function above to replace the line that is in our text file, to the file userspw.py, with the message containing
  124.     #username and password on it, with the correct format to put on the dictionary.
  125.     replace_line("userspw.py", line, message)
  126.  
  127.  
  128.  
  129. """SHA1_SUM encrypter function for resources in menu"""
  130. """This function and the one bellow,basicaly, take a string input by the user, we use the hashlib to turn it
  131. into a sha1 hash, and retrieve that hash to the user."""
  132. def sha1_sum_interface():
  133.     top = Toplevel(width=25, height=25, bg="Grey", bd=3, relief=RIDGE)
  134.     top.title("SHA1 Encrypter")
  135.  
  136.     introduction = Label(top, text="============= Be welcome to SHA1 encrypter! ============")
  137.     introduction.grid(row=0, column=0, columnspan=3)
  138.  
  139.     instructions = Label(top, text="String you want to convert:")
  140.     instructions.grid(row=1, column=0, columnspan=2, sticky=W)
  141.  
  142.     sha1_sum_interface.sha1entry = Entry(top)
  143.     sha1_sum_interface.sha1entry.grid(row=1, column=2, sticky=W)
  144.  
  145.     submit_button = Button(top, text="Submit", command=sha1_sum_code)
  146.     submit_button.grid(row=2, column=1, sticky=E)
  147.  
  148.     dimiss_button = Button(top, text="Dimiss", command=top.destroy)
  149.     dimiss_button.grid(row=2, column=2, sticky=W)
  150.  
  151.     copy_button = Button(top, text="Copy", command=copy_hash_sha1)
  152.     copy_button.grid(row=2, column=1, sticky=W)
  153.  
  154.     sha1_sum_interface.sha1_text = Text(top, width=64, height=5, wrap=WORD)
  155.     sha1_sum_interface.sha1_text.grid(row=4, column=0, columnspan=4)
  156.  
  157.  
  158. def sha1_sum_code():
  159.     string = sha1_sum_interface.sha1entry.get()
  160.     sha1_sum_code.sha1_hash = hashlib.sha1(string)
  161.     sha1_sum_code.sha1_hash = sha1_sum_code.sha1_hash.hexdigest()
  162.  
  163.     sha1_sum_interface.sha1_text.delete(0.0, END)
  164.     sha1_sum_interface.sha1_text.insert(0.0, sha1_sum_code.sha1_hash)
  165.  
  166.  
  167. """SHA1COPY BUTTON"""
  168. def copy_hash_sha1():
  169.     pyperclip.copy(sha1_sum_code.sha1_hash)
  170.     sha1_sum_interface.sha1_text.insert(0.0, "\n SHA1 string has has been sucessifuly copied.")
  171.  
  172.  
  173.  
  174. """MD5_encrypter function for resources in menu"""
  175. """Same as Sha1 but in MD5"""
  176. def md5_interface():
  177.     top = Toplevel(width=25, height=25, bd=3, relief=SUNKEN)
  178.     top.title("MD5 Encrypter")
  179.  
  180.     introduction = Label(top, text="============= Be welcome to MD5 encrypter! =============")
  181.     introduction.grid(row=0, column=0, columnspan=3)
  182.  
  183.     instructions = Label(top, text="String you want to convert:")
  184.     instructions.grid(row=1, column=0, columnspan=2, sticky=W)
  185.  
  186.     md5_interface.md5entry = Entry(top)
  187.     md5_interface.md5entry.grid(row=1, column=2, sticky=W)
  188.  
  189.     submit_button = Button(top, text="Submit", command=md5_code)
  190.     submit_button.grid(row=2, column=1, sticky=E)
  191.  
  192.     dimiss_button = Button(top, text="Dimiss", command=top.destroy)
  193.     dimiss_button.grid(row=2, column=2, sticky=W)
  194.  
  195.     copy_button = Button(top, text="Copy", command=copy_hash_md5)
  196.     copy_button.grid(row=2, column=1, sticky=W)
  197.  
  198.     md5_interface.md5_text = Text(top, width=64, height=5, wrap=WORD)
  199.     md5_interface.md5_text.grid(row=4, column=0, columnspan=4)
  200.  
  201.  
  202. def md5_code():
  203.     string = md5_interface.md5entry.get()
  204.     md5_code.md5_hash = hashlib.md5(string)
  205.     md5_code.md5_hash = md5_code.md5_hash.hexdigest()
  206.  
  207.     md5_interface.md5_text.delete(0.0, END)
  208.     md5_interface.md5_text.insert(0.0, md5_code.md5_hash)
  209.  
  210.  
  211. """MD5 COPY BUTTON"""
  212. def copy_hash_md5():
  213.     pyperclip.copy(md5_code.md5_hash)
  214.     md5_interface.md5_text.insert(0.0, "\n MD5 string has has been sucessifuly copied.")
  215.  
  216.  
  217. """Credits function, in about menu"""
  218. def credits():
  219.     top = Toplevel(width=15, height=3, bg="Grey", bd=3, relief=GROOVE)
  220.     top.title("About this application...")
  221.  
  222.     msg = Message(top,
  223.                   text="Thanks for using SenhaSafe! This program was made for eductional purposes by krec01.\n Be HAPPY <3")
  224.     msg.pack()
  225.  
  226.     dimiss_button = Button(top, text="Dimiss", command=top.destroy)
  227.     dimiss_button.pack()
  228.  
  229.  
  230. class Application(Frame):
  231.     def __init__(self, master):
  232.         Frame.__init__(self, master)
  233.         self.grid()
  234.         self.master_password()
  235.  
  236.     """Master password request menu"""
  237.  
  238.     def master_password(self):
  239.         """Instructions"""
  240.         self.master_instructions = Label(self, text="Introduce the master password to gain acess:")
  241.         self.master_instructions.grid(row=0, column=0)
  242.         """Credits"""
  243.         Label(self, text="Made by krec01, current version- v0.01").grid(row=10, column=0)
  244.         """Password entry gap with * chars"""
  245.         self.master_entry = Entry(self, show="*", width=25)
  246.         self.master_entry.grid(row=0, column=1)
  247.         """Checkbutton for plain test, leads to plain_test function"""
  248.         self.plain_test = BooleanVar()
  249.         Checkbutton(self, text="Show plain test", variable=self.plain_test, command=self.plain_test_retrieve).grid(
  250.             row=1, column=0)
  251.         """Submit button, leading to master_check function"""
  252.         self.submit_master = Button(self, text="Submit", command=self.master_check)
  253.         self.submit_master.grid(row=1, column=1, columnspan=1)
  254.         """Area where text is inserted"""
  255.         self.text = Text(self, width=71, height=6)
  256.         self.text.grid(row=5, column=0, columnspan=3)
  257.  
  258.     """Function that checks master password whenever submit button is pressed. Removes widget is pw is correct"""
  259.  
  260.     def master_check(self):
  261.         r = open("master","r")
  262.         pword = str(r.read())
  263.         if self.master_entry.get() == pword:
  264.             self.text.delete(0.0, END)
  265.             self.text.insert(0.0, "\nCorrect password! Acess Garanted")
  266.             self.master_entry.grid_remove()
  267.             self.submit_master.grid_remove()
  268.             self.master_instructions.grid_remove()
  269.             """Leading to create_widgets function"""
  270.             return self.create_widgets()
  271.         else:
  272.             self.text.delete(0.0, END)
  273.             self.text.insert(0.0, "Wrong Password! Acess Denied.")
  274.  
  275.     """This block is activated whenever plain_test checkbutton is pressed"""
  276.  
  277.     def plain_test_retrieve(self):
  278.         if self.plain_test.get() == True:
  279.             self.master_entry.config(show="")
  280.         else:
  281.             self.master_entry.config(show="*")
  282.  
  283.     def create_widgets(self):
  284.         """Instructions"""
  285.         Label(self, text="Welcome to PwBanker!").grid(row=0, column=0)
  286.         Label(self, text="Introduce your username:").grid(row=1, column=0)
  287.         """Checks for "userspw" file, creates one if isn't presented"""
  288.         try:
  289.             with open("userspw.py", "r") as senhas:
  290.                 self.text.insert(0.0, "userspw.py file detected!...")
  291.                 senhas.read()
  292.         except:
  293.             # mysenha = open("userspw.py", "a")
  294.             # mysenha.write("This file passwords are protected with encryption".center(50, "#="))
  295.             # mysenha.close()
  296.             self.text.insert(0.0, "userspw.py file created in current directory!...")
  297.         """Requesting password in dictionary"""
  298.         self.username = Entry(self,width=25)
  299.         self.username.grid(row=1, column=1)
  300.  
  301.         """Button that copys to clipboard the password"""
  302.         self.submit_un = Button(self, text="Retrieve Password!", command=self.username_check)
  303.         self.submit_un.grid(row=2, column=0)
  304.  
  305.     def username_check(self):
  306.         if self.username.get() in userspw.updic0.keys():
  307.             self.user_name = self.username.get()
  308.             self.user_password = userspw.updic0[self.username.get()]
  309.             self.password_message = "Username:" + " " + self.user_name + "\nPassword:" + self.user_password + "\n"
  310.             self.text.insert(0.0, self.password_message)
  311.         else:
  312.             self.text.insert(0.0, "Username not found\n")
  313.  
  314.  
  315. root = Tk()
  316. root.title("PwBanker")
  317. root.geometry("500x300+200+200")
  318. app = Application(root)
  319.  
  320. mymenu = Menu(root)
  321. root.config(menu=mymenu)
  322.  
  323. subMenuFile = Menu(mymenu)
  324. mymenu.add_cascade(label="File", menu=subMenuFile)
  325. subMenuFile.add_command(label="New account", command=new_account)
  326. subMenuFile.add_command(label="Exit", command=exit)
  327.  
  328. subMenuResources = Menu(mymenu)
  329. mymenu.add_cascade(label="Resources", menu=subMenuResources)
  330. subMenuResources.add_command(label="SHA1-SUM Encrypter", command=sha1_sum_interface)
  331. subMenuResources.add_command(label="MD5 Encrpyer", command=md5_interface)
  332.  
  333. subMenuAbout = Menu(mymenu, tearoff=0)
  334. mymenu.add_cascade(label="About", menu=subMenuAbout)
  335. subMenuAbout.add_command(label="About this application...", command=credits)
  336.  
  337. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement