Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import random #random integers
- import base64 #encryption
- import tkinter #gui
- import getpass #hiding password input
- import re #character filter
- import os #file management
- import sys #file management
- import shutil #file management
- #establishing variables
- #account creation variables
- account_created = False;
- #security quesion creation variables
- security_question_creation=False;
- sq1_verified=True
- sq2_verified=True
- sq3_verified=True
- sq_verfication = set("1one2two3three")
- first_run=True
- #sign-in variables
- verification_complete = False;
- verification_attempts = 6
- verification_delay = False;
- username_missmatch=False
- #username changing variables
- username_change_complete = False;
- #password changing variables
- old_attempts = 6
- old_delay = False;
- password_change_complete = False;
- #password recovery variables
- password_recovery_complete = False;
- recovery_attempts=2
- x=random.randint(1,3)
- #miscellaneous variables
- password_delay=3 #set to 30 for final version
- selection = ""
- username=""
- #encryption
- def encrypt(message):
- key="LxsAEgwYRQIGRRAKEhdP"
- enc = []
- for i in range(len(message)):
- key_c = key[i % len(key)]
- enc_c = chr((ord(message[i]) + ord(key_c)) % 256)
- enc.append(enc_c)
- return base64.urlsafe_b64encode("".join(enc).encode()).decode()
- #file management
- def read(file):
- f = open(file, "r")
- string=(f.read)()
- string=str(string)
- f.close()
- return string
- def save(data, file):
- f= open(file,"w+")
- f.write(data)
- f.close()
- def save_as_encrypted(data, file):
- f= open(file,"w+")
- f.write(encrypt(data))
- f.close()
- #selection menu
- def selection1():
- global selection
- selection = int(1)
- selection_menu.destroy()
- def selection2():
- global selection
- selection = int(2)
- selection_menu.destroy()
- def selection3():
- global selection
- selection = int(3)
- selection_menu.destroy()
- def selection4():
- global selection
- selection = int(4)
- selection_menu.destroy()
- def selection5():
- global selection
- selection = int(5)
- selection_menu.destroy()
- def exit():
- quit()
- def createFolder(directory):
- try:
- if not os.path.exists(directory): #createFolder("./data/")
- os.makedirs(directory)
- except OSError:
- print ("Error: Creating directory. " + directory)
- ################PROGRAM STARTS################
- while(selection==""):
- selection_menu = tkinter.Tk()
- selection_menu.title("Selection")
- label = tkinter.Label(selection_menu, text="Press a button to continue:\n", font="none 12 bold")
- button = tkinter.Button(selection_menu, text="Sign In", command=selection1)
- button2 = tkinter.Button(selection_menu, text="Create An Account", command=selection2)
- button3 = tkinter.Button(selection_menu, text="Change Username", command=selection3)
- button4 = tkinter.Button(selection_menu, text="Change Password", command=selection4)
- button5 = tkinter.Button(selection_menu, text="Account Recovery []", command=selection5)
- button6 = tkinter.Button(selection_menu, text="Exit", command=exit)
- label.pack()
- button.pack()
- button2.pack()
- button3.pack()
- button4.pack()
- button5.pack()
- button6.pack()
- selection_menu.geometry("240x220")
- selection_menu.mainloop()
- while(verification_complete==False):
- #sign-in process
- if(selection==1):
- if(username=="" or username_missmatch==True):
- username=input("Please enter your USERNAME: ")
- username_missmatch=False
- else:
- if(os.path.exists("./" + str(username))==True):
- password=read("./" + str(username) + "/password.txt")
- if(int(verification_attempts)==0):
- print("Too many unsuccessful attempts. Please try again later\n")
- time.sleep(3)
- input("\nPress [ENTER] to Exit")
- exit()
- else:
- if(int(verification_attempts)==3 and verification_delay==False):
- print("Too many unsuccessful attempts. Please try again in 30 seconds\n")
- verification_delay=True
- time.sleep(password_delay)
- else:
- passcheck=encrypt((getpass.getpass("Please enter your PASSWORD (NOTE: Your input will be hidden): ")))
- if passcheck==password:
- verification_complete = True
- else:
- verification_attempts=verification_attempts - 1
- print("Password incorrect. You have " + str(verification_attempts) + " attempts remaining\n")
- else:
- print("That username does not match. Please check you have typed it correctly or CREATE AN ACCOUNT if you havent already done so.\n")
- username_missmatch=True
- else:
- #password creation
- if(selection==2):
- while(account_created==False):
- username=input("Please enter your desired username (NOTE: You may ONLY use characters a-z and it MUST be between 5 and 15 characters long): ")
- if(os.path.exists("./" + str(username) + "/")==False):
- if not re.match("^[a-z]*$", username):
- print("Your username may only contain letters a-z. Please try again.\n")
- time.sleep(1)
- else:
- if len(username) > 15 or len(username) < 5:
- print("Username Must be between 5 and 15 characters long. Please try again.\n")
- time.sleep(1)
- else:
- password=(getpass.getpass("\nPlease enter your desired password. It must contain AT LEAST 6 characters (NOTE: Your input will be hidden): "))
- if len(password)<6:
- print("Password must be AT LEAST 6 characters long. Please try again.\n")
- time.sleep(1)
- else:
- passcheck=(getpass.getpass("Please re-enter your desired password (NOTE: Your input will be hidden): "))
- if passcheck==password:
- createFolder("./" + str(username) + "/")
- account_created = True
- save_as_encrypted(password, "./" + str(username) + "/password.txt.")
- print("\n")
- while(security_question_creation==False):
- if(first_run==True or sq1_verified==False):
- sq1=input("Please enter your first security question: ")
- sq1a=input("Please type the answer for your first security question: ")
- if(first_run==True or sq2_verified==False):
- sq2=input("\nPlease enter your second security question: ")
- sq2a=input("Please type the answer for your second security question: ")
- if(first_run==True or sq3_verified==False):
- sq3=input("\nPlease enter your third security question: ")
- sq3a=input("Please type the answer for your third security question: ")
- print("\nPlease take a moment to check the follwing questions: \n\n")
- print("Security Question : " + sq1 + "\nSecurity Question Answer: " + sq1a + "\n\n")
- print("Security Question : " + sq2 + "\nSecurity Question Answer: " + sq2a + "\n\n")
- print("Security Question : " + sq3 + "\nSecurity Question Answer: " + sq3a + "\n\n")
- first_run=False
- security_question_check=input("If the FIRST question is INCORRECT type 1\nIf the SECOND question is INCORRECT press 2\nIf the THIRD question is INCORRECT press 3\n\nIf all of these question are CORRECT press [ENTER] ")
- if any((c in sq_verfication)for c in security_question_check):
- q1check = set("1one,")
- q2check = set("2two")
- q3check = set("3three")
- if any((c in q1check)for c in security_question_check):
- sq1_verified=False
- else:
- sq1_verified=True
- if any((c in q2check)for c in security_question_check):
- sq2_verified=False
- else:
- sq2_verified=True
- if any((c in q3check)for c in security_question_check):
- sq3_verified=False
- else:
- sq3_verified=True
- else:
- save(sq1, "./" + str(username) + "/sq1.txt.")
- save(sq2, "./" + str(username) + "/sq2.txt.")
- save(sq3, "./" + str(username) + "/sq3.txt.")
- save_as_encrypted(sq1a, "./" + str(username) + "/sq1a.txt.")
- save_as_encrypted(sq2a, "./" + str(username) + "/sq2a.txt.")
- save_as_encrypted(sq3a, "./" + str(username) + "/sq3a.txt.")
- security_question_creation=True
- input("\nAccount successfuly created!\n\nPress [ENTER] to Exit")
- exit()
- else:
- print("Passwords do not match. Please try again.\n")
- time.sleep(1)
- else:
- print("Sorry that username is already taken! Please enter a different one.\n")
- time.sleep(1)
- else:
- #username changing
- if(selection==3):
- old_username=input("Please enter your CURRENT username: ")
- if(os.path.exists("./" + old_username + "/")==True):
- password=read("./" + str(old_username) + "/password.txt")
- while(username_change_complete == False):
- if(int(old_attempts)==0):
- print("Too many unsuccessful attempts. Please try again later\n")
- time.sleep(3)
- input("\nPress [ENTER] to Exit")
- exit()
- else:
- if(int(old_attempts)==3 and old_delay==False):
- print("Too many unsuccessful attempts. Please try again in 30 seconds\n")
- old_delay=True
- time.sleep(password_delay)
- else:
- passcheck=encrypt((getpass.getpass("Please enter your PASSWORD (NOTE: Your input will be hidden): ")))
- if(password==passcheck):
- new_username=input("Please enter your NEW username. (NOTE: You may ONLY use characters a-z and it MUST be between 5 and 15 characters long): ")
- if len(new_username) > 15 or len(new_username) < 5:
- print("Username Must be between 5 and 15 characters long. Please try again.\n")
- else:
- os.rename(str(old_username), str(new_username))
- username_change_complete = True
- print("Username change successful")
- input("\nPress [ENTER] to Exit")
- exit()
- else:
- old_attempts=old_attempts - 1
- print("Password incorrect. You have " + str(old_attempts) + " attempts remaining\n")
- else:
- print("That username does not match. Please check you have typed it correctly or CREATE AN ACCOUNT if you havent already done so.\n")
- else:
- #password changing
- if(selection==4):
- username=input("Please enter your USERNAME: ")
- if(os.path.exists("./" + username + "/")==True):
- old_password=read("./" + str(username) + "/password.txt")
- while(username_change_complete == False):
- if(int(old_attempts)==0):
- print("Too many unsuccessful attempts. Please try again later\n")
- time.sleep(3)
- input("\nPress [ENTER] to Exit")
- exit()
- else:
- if(int(old_attempts)==3 and old_delay==False):
- print("Too many unsuccessful attempts. Please try again in 30 seconds\n")
- old_delay=True
- time.sleep(password_delay)
- else:
- old_passcheck=encrypt((getpass.getpass("Please enter your CURRENT password (NOTE: Your input will be hidden): ")))
- if(old_password==old_passcheck):
- password=((getpass.getpass("Please enter your new password. It must contain AT LEAST 6 characters (NOTE: Your input will be hidden): ")))
- if len(password)<6:
- print("Password must be AT LEAST 6 characters long.")
- else:
- passcheck=((getpass.getpass("Please re-enter your new password (NOTE: Your input will be hidden): ")))
- if passcheck==password:
- save_as_encrypted(password, "./" + str(username) + "/password.txt")
- password_change_complete = True
- print("Password change successful")
- input("\nPress [ENTER] to Exit")
- exit()
- else:
- old_attempts=old_attempts - 1
- print("Old password incorrect. You have " + str(old_attempts) + " attempts remaining\n")
- else:
- print("That username does not match. Please check you have typed it correctly or CREATE AN ACCOUNT if you havent already done so.\n")
- else:
- if(selection==5):
- username=input("Please enter your USERNAME: ")
- if(os.path.exists("./" + str(username) + "/")==True):
- security_question=read("./" + str(username) + "/sq" + str(x) + ".txt")
- security_question_answer=read("./" + str(username) + "/sq" + str(x) + "a.txt")
- if(int(recovery_attempts!=0)):
- while(password_recovery_complete==False):
- user_answer=encrypt(input("Please answer the following security question: " + security_question + " "))
- if(user_answer== security_question_answer):
- print("Security question correct.")
- password_recovery_complete=True
- print("\nAt this point there would be an option to send a recovery email or something but I can't do that yet sorry!")
- input("\nPress [ENTER] to Exit")
- exit()
- else:
- revcovery_attempts=recovery_attempts-1
- print("Security question incorrect. You have " + str(attempts) + " attempts remaining to protect your data.")
- else:
- print("Too many unsuccessful attempts. Please try again later")
- time.sleep(3)
- exit()
- input("\nPress [ENTER] to Exit")
- exit()
- else:
- print("That username does not match. Please check you have typed it correctly or CREATE AN ACCOUNT if you havent already done so.\n")
- #anything you want when signed in goes here.
- print("You are now signed in!")
- input("\nPress [ENTER] to Exit")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement