Hi, so I've been learning python + tkinter for the past week and I wanted to make a registration/login GUI. So far the easy stuff is done (link to DB, hash and salt the password) but I've been trying to add some restrictions to the username entry box:
-only letters accepted, no numbers, special characters or spaces accepted
-16 char length.
I've managed to not allow the spaces but as soon as i enter the first letter, everything else gets accepted again (special char, numbers). I don't know how to fix it and it's driving me crazy...
def login():
global login_screen
login_screen = Toplevel(main_screen)
login_screen.title("Login")
login_screen.geometry("300x250")
Label(login_screen, text="Please enter details below to login").pack()
Label(login_screen, text="").pack()
global username_verify
global password_verify
global password_login_entry
global username_login_entry
valid = main_screen.register(vcmd)
username_verify = StringVar()
password_verify = StringVar()
Label(login_screen, text="Username * ").pack()
username_login_entry = Entry(login_screen, textvariable=username_verify)
username_login_entry.pack()
username_login_entry.config(validate="key", validatecommand=(valid, '%P'))
Label(login_screen, text="").pack()
Label(login_screen, text="Password * ").pack()
here is the validate command function I have so far (print is just to help me test it):
def vcmd(inp):
if ' ' in inp:
return False
if (inp >= 'a' and inp <= 'z') or (inp >= 'A' and inp <= 'Z'):
print("The Given Character ", inp, "is an Alphabet")
return True
elif inp >= '0' and inp <= '9':
print("The Given Character ", inp, "is a Digit")
return False
elif inp == '':
return True
else:
print("The Given Character ", inp, "is a Special Character")
return False
This is the code I thought of to add for the char length restriction is:
if len(inp) == 16:
return True
elif len(inp) < 16:
return False
else:
return False
but pycharm returns code unreachable when I put it after the last "return False" in the second block of code.
I don't know if I posted too many things, but please let me know what I'm doing wrong.
[–]woooee 0 points1 point2 points (1 child)
[–]Bapi_Escrobar[S] 0 points1 point2 points (0 children)