I've been assigned a piece of homework to add a tkinter GUI to normal python code.
This is my code:
from tkinter import *
Window = Tk()
PasswordActual = Entry(Window)
Password = str(PasswordActual)
L1 = Label(Window, text = "Enter password:")
L2 = Label(Window)
def Main():
PasswordCheck1 = len(Password)
NumbersList = []
CapsList = []
LowersList = []
def PasswordProcesser(WhatCharacters, CharactersInPassword):
for Characters in WhatCharacters:
if Characters in Password:
PasswordCheck2 = Characters in Password
if CharactersInPassword == "Numbers":
NumbersList.append(PasswordCheck2)
elif CharactersInPassword == "Caps":
CapsList.append(PasswordCheck2)
elif CharactersInPassword == "Lowers":
LowersList.append(PasswordCheck2)
if PasswordCheck1 >= 6 and PasswordCheck1 <= 12:
PasswordProcesser(["1","2","3","4","5","6","7","8","9"], "Numbers")
PasswordProcesser(["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","Q","Y","Z"], "Caps")
PasswordProcesser(["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"], "Lowers")
NumbersInPassword = sum(NumbersList)
CapsInPassword = sum(CapsList)
LowersInPassword = sum(LowersList)
if NumbersInPassword == 0 and CapsInPassword == 0 and LowersInPassword > 0 or CapsInPassword == 0 and NumbersInPassword > 0 and LowersInPassword == 0 or LowersInPassword == 0 and CapsInPassword > 0 and NumbersInPassword == 0:
L2.configure(text = "Password is weak")
elif NumbersInPassword == 0 and CapsInPassword > 0 and LowersInPassword > 0 or CapsInPassword == 0 and LowersInPassword > 0 and NumbersInPassword > 0 or LowersInPassword == 0 and NumbersInPassword > 0 and CapsInPassword > 0:
L2.configure(text = "Password is medium")
else:
L2.configure(text = "Password is strong")
else:
L2.configure(text = "Password too long or short")
Checker = Button(Window, text = "Check Password", command = Main)
L1.grid(row = 1, column = 1)
PasswordActual.grid(row = 1, column = 2)
Checker.grid(row = 2, column = 1)
L2.grid(row = 2, column = 2)
My desired output tells the user that his or her code is weak, medium or strong. It works without the added tkinter stuff but it repeatedly tells me that my password is weak. Is there any reason for this, or am I just being stupid? (I'm a tkinter beginner) Thx in advance.
This is my (working) code without GUI:
def Main2():
Password = input("What is your password?: ")
PasswordCheck1 = len(Password)
NumbersList = []
CapsList = []
LowersList = []
def ExitFunc():
Exit = input("Do you want to exit or retry?: ")
if Exit == "exit" or Exit == "Exit":
exit
elif Exit == "retry" or Exit == "Retry":
Main2()
else:
print("Invalid input, enter exit or retry")
ExitFunc()
def PasswordProcesser(WhatCharacters, CharactersInPassword):
for Characters in WhatCharacters:
if Characters in Password:
PasswordCheck2 = Characters in Password
if CharactersInPassword == "Numbers":
NumbersList.append(PasswordCheck2)
elif CharactersInPassword == "Caps":
CapsList.append(PasswordCheck2)
elif CharactersInPassword == "Lowers":
LowersList.append(PasswordCheck2)
if PasswordCheck1 >= 6 and PasswordCheck1 <= 12:
PasswordProcesser(["1","2","3","4","5","6","7","8","9"], "Numbers")
PasswordProcesser(["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","Q","Y","Z"], "Caps")
PasswordProcesser(["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"], "Lowers")
NumbersInPassword = sum(NumbersList)
CapsInPassword = sum(CapsList)
LowersInPassword = sum(LowersList)
if NumbersInPassword == 0 and CapsInPassword == 0 and LowersInPassword > 0 or CapsInPassword == 0 and NumbersInPassword > 0 and LowersInPassword == 0 or LowersInPassword == 0 and CapsInPassword > 0 and NumbersInPassword == 0:
print("Password is weak, try and include capital, lowercase and numerical characters")
ExitFunc()
elif NumbersInPassword == 0 and CapsInPassword > 0 and LowersInPassword > 0 or CapsInPassword == 0 and LowersInPassword > 0 and NumbersInPassword > 0 or LowersInPassword == 0 and NumbersInPassword > 0 and CapsInPassword > 0:
print("Password is medium, try and include capital, lowercase and numerical characters")
ExitFunc()
else:
print("Password is strong")
ExitFunc()
else:
print("Password too long or short, it needs to be no shorter than 6 and no longer than 12")
ExitFunc()
Main2()