I'm trying to figure out how to write a program that will accept username, password, login button, sign up button and eventually have some sort of password encryption. Currently The code is a main window and when signup is clicked a pop up window. I will adjust the code to reflect changes I make when/as they are confirmed for "live" edition. currently I am working on registration window progress
The part I'm wanting help with currently is when you click login on the root window currently it prints to idle "username/password entered: ____ ". I would like to know how can I store & encrypt the username/password. (I will most likely add an option to include email on the registration window which would presumably also need to be encrypted and saved)
I had the idea of possibly doing a ceasar cipher but, in terms of security It probably isn't ideal to write a ceasar cipher to convert each individual letter to a 10 digit alphanumerical with 5 digits (15 total 5 numbers & 10 letters) randomized? is there a better/ more ideal option for the encryption/decryption process. I did find a few encryption options but many of them were using multiple languages such as sql, flask, Django which very quickly went over my head and made it difficult to progress
Any and all recommendations on code/formatting are appreciated
from tkinter import *
from functools import partial
def validateLogin(username, password):
print("username entered :", username.get())
print("password entered :", password.get())
return
def open_win():
registration=Toplevel(root)
registration.title("Registration Page")
window_width=600
window_height=400
screen_width =registration.winfo_screenwidth()
screen_height =registration.winfo_screenheight()
center_x=int(screen_width/2-window_width/2)
center_y=int(screen_height/2-window_height/2)
registration.geometry(f'{window_width}x{window_height} {center_x} {center_y}')
#window
root=Tk()
root.title('Sign in Page')
#centering window
window_width=600
window_height=400
screen_width =root.winfo_screenwidth()
screen_height =root.winfo_screenheight()
center_x=int(screen_width/2-window_width/2)
center_y=int(screen_height/2-window_height/2)
root.geometry(f'{window_width}x{window_height} {center_x} {center_y}')
#username label and text entry box
usernameLabel=Label(root, text="User Name").grid(row=0, column=1)
username=StringVar()
usernameEntry=Entry(root, textvariable=username).grid(row=0, column=2)
#password label and password entry box
passwordLabel=Label(root,text="Password").grid(row=1, column=1)
password=StringVar()
passwordEntry=Entry(root, textvariable=password, show='*').grid(row=1, column=2)
validateLogin=partial(validateLogin, username, password)
#login button
loginButton=Button(root, text="Login", command=validateLogin).grid(row=4, column=1)
SignUpButton=Button(root, text="Sign up", command=open_win).grid(row=4, column=2)
root.mainloop()
CodePudding user response:
Use files for when a user signs up
def onSignup(UserName,EncryptedPassword):
f = open(UserName,"w")
f.write(EncryptedPassword)
f.close()
For encryption, there are a ton of encryption libraries but I would recommend using one that does not decrypt. Just encrypt the password given and check it to the encrypted password in the file and then you have your result. No need for decryption!